• 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--鼠标放开事件");
    			}
    			
    		});
    	}
    
    }
    
    
  • 相关阅读:
    Hystrix源码分析(一)
    docker虚拟ip和项目地ip冲突问题解决
    Hystrix入门demo
    为什么spirng扫描到@compent会把对象注册到容器上
    hive安装与基本操作
    hadoop基本安装
    spring session 存到数据库的设置
    React加Ant Design实现的一个登陆界面及小案例
    一个获取天气预报数据的小案例
    React学习笔记案例2
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13076534.html
Copyright © 2020-2023  润新知