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:

  • 相关阅读:
    webNav
    keyBoardValue
    认证,权限,频率
    路由组件与视图集中附加action的声明
    视图组件
    请求与响应
    DRF序列化组件
    DRF入门及安装
    后台管理
    auth认证模块
  • 原文地址:https://www.cnblogs.com/lianghong881018/p/11274175.html
Copyright © 2011-2022 走看看