java抓取鼠标事件和鼠标滚轮事件示例
java抓取鼠标事件和滚轮事件
package demo;
import java.awt.event.mouseevent;
import java.awt.event.mouselistener;
import java.awt.event.mousewheelevent;
import java.awt.event.mousewheellistener;
import javax.swing.jbutton;
import javax.swing.jframe;
import javax.swing.jpanel;
public class mousedemo extends jframe implements mouselistener,mousewheellistener{
static int chang=400,kuang=400;
public mousedemo(){
jpanel j=new jpanel();
jbutton jb=new jbutton("click");
j.add(jb);
this.add(j);
this.setvisible(true);
this.setsize(chang,kuang);
jb.addmouselistener(this);
this.addmousewheellistener(this);
}
public void mouseclicked(mouseevent e){
//左击事件
if(e.getbutton()==mouseevent.button1)
system.out.println("zuo ji shi jian ....");
//滑轮按下事件
if(e.getbutton()==mouseevent.button2)
system.out.println("zhong ji shi jian ....");
//右击事件
if(e.getbutton()==mouseevent.button3)
system.out.println("you ji shi jian ....");
}
public static void main(string[] args) {
// todo auto-generated method stub
new mousedemo();
}
@override
public void mouseentered(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mouseexited(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mousepressed(mouseevent e) {
// todo auto-generated method stub
}
@override
public void mousereleased(mouseevent e) {
// todo auto-generated method stub
}
@override
//利用滚轮事件将窗口放大和缩小
public void mousewheelmoved(mousewheelevent e) {
// todo auto-generated method stub
if(e.getwheelrotation()==1){
chang+=10;
kuang+=10;
this.setsize(chang,kuang);
this.validate();
system.out.println("滑轮向前。。。。");
}
if(e.getwheelrotation()==-1){
chang-=10;
kuang-=10;
this.setsize(chang,kuang);
this.validate();
system.out.println("滑轮向后....");
}
}
}
上一篇: java根据url抓取并生成缩略图的示例
推荐阅读
-
java抓取鼠标事件和鼠标滚轮事件示例
-
java selenium3开发(十):鼠标的单击双击右键等事件
-
javascript简单拖拽鼠标事件mousedown和mousemove以及mouseup实例分析
-
鼠标滚轮事件滚动有Flash动画的网页
-
浅谈Javascript鼠标和滚轮事件_javascript技巧
-
javascript实现在某个元素上阻止鼠标右键事件的方法和实例_javascript技巧
-
Python中使用PyHook监听鼠标和键盘事件实例
-
Jquery使用mouseenter和mouseleave事件实现鼠标经过弹出层且可以点击的示例代码分享
-
【UWP】多个ScrollViewer嵌套时鼠标滚轮事件的处理
-
jQuery事件mouseover和mouseout在鼠标经过子元素时也会触发详解