button.addMouseListener(new MouseAdapter(){ public void mousePressed(MouseEvent e){ if(e.getButton()== } });
getButton public int getButton() Returns which, if any, of the mouse buttons has changed state. Returns: one of the following constants: NOBUTTON, BUTTON1, BUTTON2 or BUTTON3. Since: 1.4 右击返回的是BUTTON3
import java.awt.Button; import java.awt.Frame; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent;public class ButtonEvent { public static void main(String[] args) { Frame f =new Frame(); Button b = new Button("eeee"); b.addMouseListener(new MouseAdapter(){ public void mousePressed(MouseEvent e){ if(e.getButton()== e.BUTTON1) { System.out.println("左击"); } if(e.getButton()== e.BUTTON2) { System.out.println("中击"); } if(e.getButton()==e.BUTTON3) { System.out.println("右击"); } } }); f.add(b); f.setVisible(true); }}
public void mousePressed(MouseEvent e){
if(e.getButton()==
}
});
public int getButton()
Returns which, if any, of the mouse buttons has changed state. Returns:
one of the following constants: NOBUTTON, BUTTON1, BUTTON2 or BUTTON3.
Since:
1.4 右击返回的是BUTTON3
import java.awt.Button;
import java.awt.Frame;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;public class ButtonEvent {
public static void main(String[] args) {
Frame f =new Frame();
Button b = new Button("eeee");
b.addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent e){
if(e.getButton()== e.BUTTON1)
{
System.out.println("左击");
}
if(e.getButton()== e.BUTTON2)
{
System.out.println("中击");
}
if(e.getButton()==e.BUTTON3)
{
System.out.println("右击");
}
} });
f.add(b);
f.setVisible(true);
}}
mouseEvent.getModifiersEx()