Example usage for java.awt.event MouseEvent getY

List of usage examples for java.awt.event MouseEvent getY

Introduction

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

Prototype

public int getY() 

Source Link

Document

Returns the vertical y position of the event relative to the source component.

Usage

From source file:XORModePaintWithMouse.java

XORModePaintWithMouse() {
    addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseMoved(MouseEvent me) {
            int x = me.getX();
            int y = me.getY();
            chsX = x - 10;//from w  ww.j a  v  a  2s  .  c o m
            chsY = y - 10;
            repaint();
        }
    });
}

From source file:Main.java

public PopupMenu() {
    super(BoxLayout.Y_AXIS);
    final JPopupMenu menu = new JPopupMenu("Options");
    for (int i = 1; i < 20; i++)
        menu.add(new JMenuItem("Option" + i));

    JLabel clickMe = new JLabel("ClickMe");
    clickMe.setAlignmentX(RIGHT_ALIGNMENT);
    clickMe.addMouseListener(new MouseAdapter() {
        @Override/*from ww  w. j a v a  2s.  c o m*/
        public void mouseClicked(MouseEvent e) {
            menu.show(e.getComponent(), e.getX(), e.getY());
        }
    });
    add(clickMe);
}

From source file:ClippedDragImage.java

public void mouseDragged(MouseEvent e) {
    imageX = e.getX();//w  w  w  . j  av a  2s  .c  o  m
    imageY = e.getY();
    Rectangle r = getAffectedArea(oldX, oldY, imageX, imageY, imageWidth, imageHeight);
    repaint(r); // repaint just the affected part of the component
    oldX = imageX;
    oldY = imageY;
}

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  ww.j a  v a 2 s . c o  m
    });
}

From source file:MainClass.java

public MyCanvas() {
    addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent me) {
            TextHitInfo hit = mTextLayout.hitTestChar(me.getX() - mX, me.getY() - mY);
            System.out.println(hit.getCharIndex());
            System.out.println(hit.getInsertionIndex());
            System.out.println(hit.isLeadingEdge());
        }/*from   w  ww .j  a  v a2s  . c  o m*/
    });

}

From source file:SimpleDraw.java

public void mousePressed(MouseEvent me) {
    x1 = me.getX();
    y1 = me.getY();
}

From source file:Main.java

private void myPopupEvent(MouseEvent e) {
    int x = e.getX();
    int y = e.getY();
    JTree tree = (JTree) e.getSource();
    TreePath path = tree.getPathForLocation(x, y);
    if (path == null)
        return;//w w w .  j av a 2  s .com

    DefaultMutableTreeNode rightClickedNode = (DefaultMutableTreeNode) path.getLastPathComponent();

    TreePath[] selectionPaths = tree.getSelectionPaths();

    boolean isSelected = false;
    if (selectionPaths != null) {
        for (TreePath selectionPath : selectionPaths) {
            if (selectionPath.equals(path)) {
                isSelected = true;
            }
        }
    }
    if (!isSelected) {
        tree.setSelectionPath(path);
    }
    if (rightClickedNode.isLeaf()) {
        JPopupMenu popup = new JPopupMenu();
        final JMenuItem refreshMenuItem = new JMenuItem("refresh");
        refreshMenuItem.addActionListener(ev -> System.out.println("refresh!"));
        popup.add(refreshMenuItem);
        popup.show(tree, x, y);
    }
}

From source file:Main.java

public DrawPad() {
    setDoubleBuffered(false);//from w w  w  . j  ava  2  s  .  c  o  m
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            oldX = e.getX();
            oldY = e.getY();
        }
    });
    addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseDragged(MouseEvent e) {
            currentX = e.getX();
            currentY = e.getY();
            if (graphics2D != null)
                graphics2D.drawLine(oldX, oldY, currentX, currentY);
            repaint();
            oldX = currentX;
            oldY = currentY;
        }
    });
}

From source file:SimpleDraw.java

public void mouseReleased(MouseEvent me) {
    x2 = me.getX();/*from   w  ww.  ja  va2  s  . c  o  m*/
    y2 = me.getY();
    Shape shape = null;
    if (shapeType.equals("Rectangle")) {
        // a Rectangle cannot have a zero width or height
        if (x1 != x2 || y1 != y2) {
            shape = new Rectangle(x1, y1, x2, y2);
        }
    }
    if (shape != null) {
        this.shapes.add(shape);
        this.repaint();
    }
}

From source file:SaveYourDrawingToFile.java

public void mousePressed(MouseEvent e) {
    Point p = new Point(e.getX(), e.getY());
    displayList.add(p);
}