zoukankan      html  css  js  c++  java
  • Java GUI 鼠标事件

    import java.awt.Button;
    import java.awt.FlowLayout;
    import java.awt.Frame;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    
    public class Java鼠标事件 {
    	public static void main(String[] args) {
    		Frame f = new Frame("WindowEvent");
    		f.setLayout(new FlowLayout());
    		f.setSize(300,200);
    		f.setLocation(300, 200);
    		f.setVisible(true);
    		Button btn = new Button("Button");
    		f.add(btn);
    		btn.addMouseListener(new MouseAdapter() {
    
    			@Override
    			public void mouseClicked(MouseEvent e) {
    				// TODO Auto-generated method stub
    			System.out.println("MouseClicked--鼠标完成点击事件");	
    			if(e.getButton()==e.BUTTON1) {
    				System.out.println("鼠标左击事件");
    			}
    			else if(e.getButton()==e.BUTTON2) {
    				System.out.println("鼠标中键点击事件");				
    			}
    			else if (e.getButton()==e.BUTTON3) {
    				System.out.println("鼠标右击事件");
    			}
    			}
    
    			@Override
    			public void mouseEntered(MouseEvent arg0) {
    				// TODO Auto-generated method stub
    				System.out.println("MouseEntered--鼠标进入按钮区域事件");
    			}
    
    			@Override
    			public void mouseExited(MouseEvent arg0) {
    				// TODO Auto-generated method stub
    				System.out.println("MouseExited--鼠标移出按钮区域事件");
    				
    			}
    
    			@Override
    			public void mousePressed(MouseEvent arg0) {
    				// TODO Auto-generated method stub
    				System.out.println("MousePressed--鼠标按下事件");
    			}
    
    			@Override
    			public void mouseReleased(MouseEvent arg0) {
    				// TODO Auto-generated method stub
    				System.out.println("MouseReleased--鼠标放开事件");
    			}
    			
    		});
    	}
    
    }
    
    
  • 相关阅读:
    字符个数统计
    面试题——字符的左右移动
    5. Longest Palindromic Substring
    Linux- AWS之EC2大数据集群定时开关机
    Openldap- 大机群身份验证服务
    Linux- 自动备份MySQL数据库脚本
    Linux- 运维
    JAVA- 切换默认的Java
    HIVE- 新建UDF范例
    Hadoop- 集群启动详解
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13075989.html
Copyright © 2011-2022 走看看