Example usage for java.awt.event InputEvent BUTTON1_MASK

List of usage examples for java.awt.event InputEvent BUTTON1_MASK

Introduction

In this page you can find the example usage for java.awt.event InputEvent BUTTON1_MASK.

Prototype

int BUTTON1_MASK

To view the source code for java.awt.event InputEvent BUTTON1_MASK.

Click Source Link

Document

The Mouse Button1 modifier constant.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Robot r = new Robot();
    r.mouseMove(35, 35);//  ww  w  .  j  a  va2  s.c  o m
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    Thread.sleep(50);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    Robot r = new Robot();
    r.mouseMove(35, 35);/* w  ww  .j av a  2 s  .  co  m*/
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    Thread.sleep(50);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Robot robot = new Robot();

    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Robot robot = new Robot();

    robot.mouseMove(200, 200);/*from www .j  a va2s.  co m*/

    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.mouseWheel(-100);
}

From source file:ButtonSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Button Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button = new JButton("Select Me");
    // Define MouseListener
    MouseListener mouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            int modifiers = mouseEvent.getModifiers();
            if ((modifiers & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) {
                System.out.println("Left button pressed.");
            }/*from   w w  w .ja va2s.c  om*/
            if ((modifiers & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK) {
                System.out.println("Middle button pressed.");
            }
            if ((modifiers & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) {
                System.out.println("Right button pressed.");
            }
        }

        public void mouseReleased(MouseEvent mouseEvent) {
            if (SwingUtilities.isLeftMouseButton(mouseEvent)) {
                System.out.println("Left button released.");
            }
            if (SwingUtilities.isMiddleMouseButton(mouseEvent)) {
                System.out.println("Middle button released.");
            }
            if (SwingUtilities.isRightMouseButton(mouseEvent)) {
                System.out.println("Right button released.");
            }
            System.out.println();
        }
    };
    // Attach listeners
    button.addMouseListener(mouseListener);
    frame.add(button, BorderLayout.SOUTH);
    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Button Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button = new JButton("Select Me");

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println("I was selected.");
        }//  w  ww. ja  va 2  s.c o  m
    };

    MouseListener mouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            int modifiers = mouseEvent.getModifiers();
            if ((modifiers & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) {
                System.out.println("Left button pressed.");
            }
            if ((modifiers & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK) {
                System.out.println("Middle button pressed.");
            }
            if ((modifiers & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) {
                System.out.println("Right button pressed.");
            }
        }

        public void mouseReleased(MouseEvent mouseEvent) {
            if (SwingUtilities.isLeftMouseButton(mouseEvent)) {
                System.out.println("Left button released.");
            }
            if (SwingUtilities.isMiddleMouseButton(mouseEvent)) {
                System.out.println("Middle button released.");
            }
            if (SwingUtilities.isRightMouseButton(mouseEvent)) {
                System.out.println("Right button released.");
            }
            System.out.println();
        }
    };

    button.addActionListener(actionListener);
    button.addMouseListener(mouseListener);

    frame.add(button, BorderLayout.SOUTH);
    frame.setSize(300, 100);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Button Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button = new JButton("Select Me");

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println("I was selected.");
        }//  w ww.j a  v a  2  s.c o m
    };

    MouseListener mouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            int modifiers = mouseEvent.getModifiers();
            if ((modifiers & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) {
                // Mask may not be set properly prior to Java 2
                // See SwingUtilities.isLeftMouseButton() for workaround
                System.out.println("Left button pressed.");
            }
            if ((modifiers & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK) {
                System.out.println("Middle button pressed.");
            }
            if ((modifiers & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) {
                System.out.println("Right button pressed.");
            }
        }

        public void mouseReleased(MouseEvent mouseEvent) {
            if (SwingUtilities.isLeftMouseButton(mouseEvent)) {
                System.out.println("Left button released.");
            }
            if (SwingUtilities.isMiddleMouseButton(mouseEvent)) {
                System.out.println("Middle button released.");
            }
            if (SwingUtilities.isRightMouseButton(mouseEvent)) {
                System.out.println("Right button released.");
            }
            System.out.println();
        }
    };

    button.addActionListener(actionListener);
    button.addMouseListener(mouseListener);

    Container contentPane = frame.getContentPane();
    contentPane.add(button, BorderLayout.SOUTH);
    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:Main.java

static boolean isLeftButtonAndNoModifiers(final MouseEvent event) {
    final boolean leftMouseButton = SwingUtilities.isLeftMouseButton(event);
    if (leftMouseButton) {
        final int modifiers = event.getModifiers();
        if (InputEvent.BUTTON1_MASK == modifiers) {
            return true;
        }/*from  w w  w. j a va 2 s.co  m*/
    }
    return false;
}

From source file:Main.java

/**
 * Returns whether event involves left mouse button or not.
 *
 * @param e//from w ww .j a  va 2  s  .c o m
 *            mouse event
 * @return true if event involves left mouse button, false otherwise
 */
public static boolean isLeftMouseButton(final MouseEvent e) {
    return (e.getModifiers() & InputEvent.BUTTON1_MASK) != 0;
}

From source file:Main.java

/**
 * Serializes a Keystrike to a String.//from ww  w .j av a2s .c o  m
 * It can then be fed into KeyStroke.getKeyStroke(String).
 *
 * See: http://www.exampledepot.com/egs/javax.swing/Key2Str.html
 */
public static String keyStroke2String(KeyStroke key) {
    StringBuffer s = new StringBuffer(50);
    int m = key.getModifiers();

    if ((m & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) {
        s.append("shift ");
    }
    if ((m & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) {
        s.append("ctrl ");
    }
    if ((m & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) {
        s.append("meta ");
    }
    if ((m & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK)) != 0) {
        s.append("alt ");
    }
    if ((m & (InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON1_MASK)) != 0) {
        s.append("button1 ");
    }
    if ((m & (InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON2_MASK)) != 0) {
        s.append("button2 ");
    }
    if ((m & (InputEvent.BUTTON3_DOWN_MASK | InputEvent.BUTTON3_MASK)) != 0) {
        s.append("button3 ");
    }

    switch (key.getKeyEventType()) {
    case KeyEvent.KEY_TYPED:
        if (key.getKeyChar() == Character.MAX_VALUE) {
            s.append("unknown-typed-key ");
            break;
        }
        s.append("typed ").append(key.getKeyChar()).append(" ");
        break;
    case KeyEvent.KEY_PRESSED:
        s.append("pressed ").append(getKeyText(key.getKeyCode())).append(" ");
        break;
    case KeyEvent.KEY_RELEASED:
        s.append("released ").append(getKeyText(key.getKeyCode())).append(" ");
        break;
    default:
        s.append("unknown-event-type ");
        break;
    }

    return s.toString();
}