- public class guidemo2 {
- public static void main(String[] args) {
- new listenerdemo();
- }
- }
- class listenerdemo
- {
- private Frame f;
- private Button b;
- private TextField tf;
- listenerdemo()
- {
- demo();
- }
- public void demo()
- {
- f = new Frame();
- b = new Button("确定");
- tf = new TextField(30);
- f.setBounds(200, 100, 300, 200);
- f.setLayout(new FlowLayout());
- f.add(b);
- f.add(tf);
- //f.setVisible(true);
- f.addWindowListener(new WindowAdapter(){
- public void windowClosing(WindowEvent e)
- {
- System.exit(0);
- }
- public void windowActivated(WindowEvent e)
- {
- System.out.println("窗体前置");
- }
- public void windowOpened(WindowEvent e)
- {
- System.out.println("窗体打开");
- }
- });
- f.setVisible(true);
- }
复制代码 f.setVisible(true);放在最后监听后边和放在监听前边,运行的效果不一样,放在前边,窗体打开时并么有输出窗体打开的文字,谁能给解释一下,
|