zoukankan      html  css  js  c++  java
  • learning java AWT widowEvent and MouseEvent

    import java.awt.*;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowListener;
    
    public class WindowListenerTest {
    
        private Frame f = new Frame();
        private TextArea ta = new TextArea(6,40);
        private Button bt  = new Button("bt");
        public void init(){
            f.addWindowListener(new MyListener());
            bt.addMouseListener(new MyMouseListener());
            f.add(bt,BorderLayout.NORTH);
            f.add(ta);
            f.pack();
            f.setVisible(true);
        }
        class MyListener  implements WindowListener{
            public void windowOpened(WindowEvent e){
                ta.append("window first be opened" +  "
    ");
            }
    
            public void windowClosed(WindowEvent e){
                ta.append("window closed " + "
    ");
                System.exit(0);
            }
    
            public void windowClosing(WindowEvent e){
                ta.append("window close by x" + "
    ");
                System.exit(0);
            }
    
            public void windowIconified(WindowEvent e){
                ta.append("window iconified be trigger" + "
    ");
            }
            public void windowDeiconified(WindowEvent e){
                ta.append("window deiconified be trigger" + "
    ");
            }
    
            public void windowActivated(WindowEvent e){
                ta.append("window activated be trigger" + "
    ");
            }
    
            public void windowDeactivated(WindowEvent e){
                ta.append("window deactivated be trigger" + "
    ");
            }
    
        };
    
        class MyMouseListener implements MouseListener{
            public void mouseEntered(MouseEvent event){
                System.out.println("mouseEntered");
            }
    
            public void mouseExited(MouseEvent event){
                System.out.println("mouseExited");
            }
            public void mouseClicked(MouseEvent event){
                System.out.println("mouseClicked");
            }
            public void mousePressed(MouseEvent event){
                System.out.println("mousePressed");
            }
            public void mouseReleased(MouseEvent event){
                System.out.println("mouseReleased");
            }
    
    
        }
    
        public static void main(String[] args) {
            new WindowListenerTest().init();
        }
    }

    output:

  • 相关阅读:
    团队冲刺第一阶段第三天
    团队冲刺第一阶段第二天
    团队冲刺第一阶段第一天
    学习进度07
    学习进度06
    结对编程之子数组最大的和(由于一直登不上我的账号,在规定日期内只在我搭档的博客上交了)
    小学四则运算网页版
    团队介绍
    学习进度条05
    111
  • 原文地址:https://www.cnblogs.com/lianghong881018/p/11274175.html
Copyright © 2011-2022 走看看