• 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:

  • 相关阅读:
    随机生成几位数
    文件下载
    动态SQL
    springmvc的xml版本和注解版本
    Hibernate与MyBatis
    关于过滤器!!
    jsp-EL表达式
    SpringMVC 自定义类型转换器
    Spring MVC 知识点记忆
    cmd的操作命令导出导入.dmp文件
  • 原文地址:https://www.cnblogs.com/lianghong881018/p/11274175.html
Copyright © 2020-2023  润新知