java小程序中鼠标事件的响应处理(包含右键、双击等)

发布时间:2024-02-19 11:28:40
javaduke 原创于 www.dukejava.com 如何在小程序中实现鼠标响应,主页提供大量java编程技巧? public class Hello extends Applet implements MouseListener{public void init(){addMouseListener(this);}public void mouseEntered(MouseEvent e){au.play();setBackground(Color.blue);}public void mouseExited(MouseEvent e){setBackground(Color.black);}public void mousePressed(MouseEvent e){}public void mouseReleased(MouseEvent e){}public void mouseClicked(MouseEvent e){}事件监听器首先在小程序中实现,如何在小程序中处理鼠标双击和三击? component.addMouseListener(new MyMouseListener());public class MyMouseListener extends MouseAdapter {public void mouseClicked(MouseEvent evt) {if (evt.getClickCount() == 3) {// 处理鼠标三击} else if (evt.getClickCount() == 2) {// 双击鼠标}}} 处理鼠标右键 public mouseClicked(MouseEvent e){ if(e.isMetaDown(){///检测鼠标右键单击 }鼠标中间键在小程序中如何处理? new MyMouseListener());public class MyMouseListener extends MouseAdapter {public void mouseClicked(MouseEvent evt) {if ((evt.getModifiers() &?InputEvent.BUTTON1__MASK) !InputEvent.BUTTON1__MASK) != 0) {processLeft(evt.getPoint());///处理鼠标左键单击}if ((evt.getModifiers() &?InputEvent.BUTTON2__MASK) != 0) {processMiddle(evt.getPoint());///单击处理鼠标中间键if ((evt.getModifiers() &?InputEvent.BUTTON3____MASK) != 0) {processRight(evt.getPoint());//处理鼠标右键单击}}
上一篇 如何加快小程序的启动速度?
下一篇 关于applet写入文件的处理

文章素材均来源于网络,如有侵权,请联系管理员删除。

标签: Java教程Java基础Java编程技巧面试题Java面试题