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--鼠标放开事件");
    			}
    			
    		});
    	}
    
    }
    
    
  • 相关阅读:
    Live Writer配置
    protobufnet 学习手记
    好的Sql语句也能提高效率(二)
    关于CodeSmith的输出问题
    [Scrum]12.29
    [scrum] 1.4
    分享 关于c#注释的规范
    [Scrum] 1.3
    分享:将XML(VS提取注释时生成)转换为Chm的一个方法
    【Scrum】2010.12.27
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13076534.html
Copyright © 2011-2022 走看看