zondag 17 april 2011

Getting Left and Right and Middle mouse buttons.

(Above is an Applet that informs you what mouse button was pressed.)

I was able to find an example of how to read the mouse buttons in Java and now know how to do it. Below some example code of how it can be done..


import java.awt.*;
import java.applet.*;

public class MouseButton01 extends Applet {
 String info="Press one of the mouse buttons in the applet";
 public void init() {

 public void paint(Graphics g) {

  g.drawString(""+info, 50, 60 );

 public boolean mouseDown (Event e, int x, int y) {
        if (e.modifiers == Event.META_MASK) {
            info=("Right Button Pressed");
        } else if (e.modifiers == Event.ALT_MASK) {
            info=("Middle Button Pressed");
        } else {
            info=("Left Button Pressed");
        return true;


Geen opmerkingen:

Een reactie posten