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) != 0) {
processLeft(evt.getPoint());
//处理鼠标左键单击
}
if ((evt.getModifiers() &?
InputEvent.BUTTON2_MASK) != 0) {
processMiddle(evt.getPoint());
//处理鼠标中间键单击
}
if ((evt.getModifiers() &?
InputEvent.BUTTON3_MASK) != 0) {
processRight(evt.getPoint());
//处理鼠标右键单击
}
}
}
如何在小程序中实现鼠标响应?
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) != 0) {
processLeft(evt.getPoint());
//处理鼠标左键单击
}
if ((evt.getModifiers() &?
InputEvent.BUTTON2_MASK) != 0) {
processMiddle(evt.getPoint());
//处理鼠标中间键单击
}
if ((evt.getModifiers() &?
InputEvent.BUTTON3_MASK) != 0) {
processRight(evt.getPoint());
//处理鼠标右键单击
}
}
}