Example usage for java.awt.event MouseAdapter MouseAdapter

List of usage examples for java.awt.event MouseAdapter MouseAdapter

Introduction

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

Prototype

MouseAdapter

Source Link

Usage

From source file:Main.java

public Main() {
    setLayout(null);//from w  w w . j av  a2 s .co m
    add(button);
    button.setSize(button.getPreferredSize());
    button.setLocation(20, 20);
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent event) {
            System.out.println(event.paramString());
        }
    });
}

From source file:Main.java

public Main() {
    setLayout(null);/*from   w  ww  .  ja v a 2 s . c  o  m*/
    add(button);
    button.setSize(button.getPreferredSize());
    button.setLocation(20, 20);
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent event) {
            System.out.println(event.isPopupTrigger());
        }
    });
}

From source file:Main.java

public Main() {
    setLayout(null);/*from  www  .j a  v a2  s.c  o  m*/
    add(button);
    button.setSize(button.getPreferredSize());
    button.setLocation(20, 20);
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent event) {
            System.out.println(event.getYOnScreen());
        }
    });
}

From source file:Main.java

public Main() {
    setLayout(null);/*from   ww w  . j  a  va2 s . c o m*/
    add(button);
    button.setSize(button.getPreferredSize());
    button.setLocation(20, 20);
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent event) {
            System.out.println(event.getPoint());
            event.translatePoint(20, 20);
            System.out.println(event.getPoint());
        }
    });
}

From source file:Main.java

public Main() {
    setLayout(null);//  ww  w.jav a2  s .  c om
    add(button);
    button.setSize(button.getPreferredSize());
    button.setLocation(20, 20);
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent event) {
            int onmask = MouseEvent.SHIFT_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK;
            int offmask = MouseEvent.CTRL_DOWN_MASK;
            if ((event.getModifiersEx() & (onmask | offmask)) == onmask) {
                System.out.println(event.getLocationOnScreen());
            }
        }
    });
}

From source file:AppletAnimation.java

public void init() {
    String str;//from   ww  w.  ja  v  a2 s  .  c o m
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            if (frozen) {
                frozen = false;
                start();
            } else {
                frozen = true;
                stop();
            }
        }
    });
}

From source file:Main.java

/**
 * Gives a tray icon a popup menu.//from  w w w .j  av a2  s.  c  o m
 *
 * @param trayIcon
 *            The tray icon
 * @param popup
 *            The popup menu
 */

public static void setPopupMenu(final TrayIcon trayIcon, final JPopupMenu popup) {
    trayIcon.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(final MouseEvent e) {
            if (e.isPopupTrigger()) {
                popup.setLocation(e.getX(), e.getY());
                popup.setInvoker(popup);
                popup.setVisible(true);
            }
        }

        @Override
        public void mouseReleased(final MouseEvent e) {
            mousePressed(e);
        }
    });
}

From source file:Main.java

public static final void addPopup(final Component c, final JPopupMenu m) {
    c.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger())
                m.show(c, e.getX(), e.getY());
        }/*from   w  w w.j  a  v  a2 s.co  m*/
    });
}

From source file:TextHitInfoDemo.java

public TextHitInfoDemo() {
    addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent me) {
            TextHitInfo hit = mTextLayout.hitTestChar(me.getX() - mX, me.getY() - mY);
            System.out.println(hit);
        }//from   w  w  w  .  jav  a  2  s .c  o m
    });
}

From source file:Main.java

private MouseListener getListener() {
    return new MouseAdapter() {
        @Override//from  w  w  w . j  a v  a 2s . com
        public void mousePressed(MouseEvent e) {
            super.mousePressed(e);
            pane.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            super.mouseReleased(e);
            pane.setCursor(Cursor.getDefaultCursor());
        }
    };
}