public class kkk extends Frame implements WindowListener
{
Font share;
TextArea text;public kkk()
{
share=new Font("Dialog",Font.PLAIN,20);
this.setLayout(null);
this.setBackground(Color.gray);
this.setSize(400, 300);
this.setVisible(true);
this.addWindowListener(this);
this.setResizable(false);text=new TextArea("座位空闲,可以入座!!!");
text.setBounds(50, 0, 300, 200);
text.setEditable(false);
text.setBackground(Color.GREEN);
text.setFont(share);
this.add(text);
}
public void windowOpened(WindowEvent e) {}
public void windowClosing(WindowEvent e) {this.dispose();}
public void windowClosed(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {} 
}
public class Test  {
public static void main(String args[])
{
kkk kk=new kkk();
}
} 为什么 TextArea中的 内容不能显示? 我把 kkk 类中的  
tthis.setLayout(null);
这句删了  就可以显示了,这是为什么呢???  急呀!!!!

解决方案 »

  1.   

    因为JFrame就没有布局,所以就不能显示了,如果要是想显示的话,在new一个新的JPanel,把JPanel加到上面,在JPanel上显示你的JTextArea ,LZ多上网查下就明白了!!
      

  2.   


    我这是  extends Frame 不是  JFrame  呀!!!
    是  TextArea  不是  JTextArea 呀!!!!
      

  3.   

    还有 你说的没有布局  ,这个根本不是问题!!!
    因为  我用了 text.setBounds(50, 0, 300, 200);
    之所以 要把布局设置为 null  就是为了 随心所欲的在任何位置 放任何大小的组件!!!