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);
这句删了 就可以显示了,这是为什么呢??? 急呀!!!!
{
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);
这句删了 就可以显示了,这是为什么呢??? 急呀!!!!
我这是 extends Frame 不是 JFrame 呀!!!
是 TextArea 不是 JTextArea 呀!!!!
因为 我用了 text.setBounds(50, 0, 300, 200);
之所以 要把布局设置为 null 就是为了 随心所欲的在任何位置 放任何大小的组件!!!