java中的鼠标事件问题(急急急!)(100分)

  • 主题发起人 主题发起人 wwwlgy
  • 开始时间 开始时间
W

wwwlgy

Unregistered / Unconfirmed
GUEST, unregistred user!
大侠救命阿
怎样在applet 中区分鼠标的左键和右键事件阿?????
 
void this_mouseClicked(MouseEvent evt) {

if(evt.getModifiers() == Event.META_MASK)
{
// Add todo
here. Right button.
}
return ;
}
 
more:
For AWT programs, you need to compare the modifiers of
the event to the button masks of the INPUT_EVENT.
Left :InputEvent.BUTTON1_MASK
Middle: InputEvent.BUTTON2_MASK
Right :InputEvent.BUTTON3_MASK
=========
For Swing programs,
the SwingUtilities class provides three support methods
todo
the INPUT_EVENT mask checking for you: isLeftMouseButton(),
isRightMouseButton(), and isMiddleMouseButton().
The meaning of left, middle, and right assumes a right-handed mouse.
Also, keep in mind that not all users have three-button mice.
While there are keyboard alternatives for the addition buttons,
consider the awkwardness for users before adding the functionality
 
public void mouseReleased/mousePressed(MouseEvent me){
int i = me.getModifiers();
if ((i &
InputEvent.BUTTON3_MASK) != 0){
System.out.println("Right mouse Released");
}else
if ((i &
InputEvent.BUTTON1_MASK) != 0){
System.out.println("Left mouse Released");
}else
{
System.out.println("Middle mouse Released");
}
}
 
多人接受答案了。
 
后退
顶部