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);
这句删了 就可以显示了,这是为什么呢??? 急呀!!!!
------解决方案--------------------
因为JFrame就没有布局,所以就不能显示了,如果要是想显示的话,在new一个新的JPanel,把JPanel加到上面,在JPanel上显示你的JTextArea ,LZ多上网查下就明白了!!