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" + "\n"); } public void windowClosed(WindowEvent e){ ta.append("window closed " + "\n"); System.exit(0); } public void windowClosing(WindowEvent e){ ta.append("window close by x" + "\n"); System.exit(0); } public void windowIconified(WindowEvent e){ ta.append("window iconified be trigger" + "\n"); } public void windowDeiconified(WindowEvent e){ ta.append("window deiconified be trigger" + "\n"); } public void windowActivated(WindowEvent e){ ta.append("window activated be trigger" + "\n"); } public void windowDeactivated(WindowEvent e){ ta.append("window deactivated be trigger" + "\n"); } }; 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: