JAVA程序鼠标监听事件大全源码 郏高阳

package AWT;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Frame;
import java.awt.TextField;
import java.awt.event.MouseListener;

public class MouseEvent {

 /**
  * @param args
  */
 
 private Frame frame;
 
 private Button button;
 
 private TextField northtext , southtext;
 
 int coun = 1;
 
 String a = " ";
 
 public MouseEvent(){

 frame = new Frame("鼠标事件");
 
 button = new Button("按钮");

 MymouseListenter ml = new MymouseListenter();
 button.addMouseListener(ml);
 
 northtext = new TextField();
 southtext = new TextField();
 button.setSize(300, 20);
 frame.add(button);
 frame.add(northtext,BorderLayout.NORTH);
 frame.add(southtext,BorderLayout.SOUTH);
 frame.setSize(500, 500);
 frame.setLocation(300, 300);
 frame.setVisible(true);
 }

 class MymouseListenter implements MouseListener{

 public void mouseClicked(java.awt.event.MouseEvent e) {
 northtext.setText("鼠标单击" + + coun + "次");
 a = a + "鼠标单击" + coun++ + "次\n" ;
 southtext.setText(a);
 }

 @Override
 public void mouseEntered(java.awt.event.MouseEvent e) {
 northtext.setText("鼠标进入组件");
 southtext.setText("鼠标进入组件!");
 
 }

 @Override
 public void mouseExited(java.awt.event.MouseEvent e) {
 // TODO Auto-generated method stub
 northtext.setText("鼠标离开");
 southtext.setText("鼠标离开!");
 
 }

 @Override
 public void mousePressed(java.awt.event.MouseEvent e) {
 northtext.setText("鼠标按下组件");
 southtext.setText("鼠标按下组件!");
 
 }

 @Override
 public void mouseReleased(java.awt.event.MouseEvent e) {
 northtext.setText("鼠标释放组件");
 southtext.setText("鼠标释放组件!");
 
 }
 
 }
 
 public static void main(String[] args) {
 new MouseEvent();
 }
}


你可能感兴趣的:(java,源码,监听,鼠标监听事件)