1. 程式人生 > >java 對滑鼠事件監視

java 對滑鼠事件監視



import java.awt.*;
import java.awt.event.*;


public class example1 {
 public static void main(String[] args){
  Frame f=new Frame("mine!!!");
  f.setLayout(new FlowLayout());
  f.setSize(800,600);
  f.setLocation(400,200);
  f.setVisible(true);
  Button btn=new Button("EXIT");
  f.add(btn);
  
  btn.addMouseListener(new MouseAdapter(){
   public void mouseClicked(MouseEvent e){
    System.out.println("wan cheng");
    System.exit(0);
   }
   public void mouseReleased(MouseEvent e){
    System.out.println("fangkai");
   }
   public void mousePressed(MouseEvent e){
    System.out.println("anxia");
   }
   public void mouseExited(MouseEvent e){
    System.out.println("yi chu");
   }
   public void mouseEntered(MouseEvent e){
    System.out.println("jin ru");
   }
  });
  }

}