List of usage examples for java.awt.event MouseEvent getY
public int getY()
From source file:SaveYourDrawingToFile.java
public void mouseReleased(MouseEvent e) { Point p = new Point(e.getX(), e.getY()); displayList.add(p); repaint(); }
From source file:Highlights.java
public Highlights() { addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent me) { firstHit = textLayout.hitTestChar(me.getX() - x, me.getY() - y); secondHit = null;// www.j av a 2s .c om } public void mouseReleased(MouseEvent me) { secondHit = textLayout.hitTestChar(me.getX() - x, me.getY() - y); repaint(); } }); addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent me) { secondHit = textLayout.hitTestChar(me.getX() - x, me.getY() - y); repaint(); } }); }
From source file:painting.SwingPaintDemo3.java
public MyPanel() { setBorder(BorderFactory.createLineBorder(Color.black)); addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { moveSquare(e.getX(), e.getY()); }//from ww w . j a v a 2 s . c o m }); addMouseMotionListener(new MouseAdapter() { public void mouseDragged(MouseEvent e) { moveSquare(e.getX(), e.getY()); } }); }
From source file:MainClass.java
public MainClass() { final JTree tree; final JTextField jtf; DefaultMutableTreeNode top = new DefaultMutableTreeNode("Options"); DefaultMutableTreeNode a = new DefaultMutableTreeNode("A"); top.add(a);//from ww w. j a v a2s .co m DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("A1"); a.add(a1); DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("A2"); a.add(a2); DefaultMutableTreeNode b = new DefaultMutableTreeNode("B"); top.add(b); DefaultMutableTreeNode b1 = new DefaultMutableTreeNode("B1"); b.add(b1); DefaultMutableTreeNode b2 = new DefaultMutableTreeNode("B2"); b.add(b2); DefaultMutableTreeNode b3 = new DefaultMutableTreeNode("B3"); b.add(b3); tree = new JTree(top); JScrollPane jsp = new JScrollPane(tree); add(jsp, BorderLayout.CENTER); jtf = new JTextField("", 20); add(jtf, BorderLayout.SOUTH); tree.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { TreePath tp = tree.getPathForLocation(me.getX(), me.getY()); if (tp != null) jtf.setText(tp.toString()); else jtf.setText(""); } }); }
From source file:MouseDragActionPanel.java
public void mouseMoved(MouseEvent evt) { int x = evt.getX(); int y = evt.getY(); if (getSquare(x, y) >= 0) setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); else//from w ww .java 2 s. c om setCursor(Cursor.getDefaultCursor()); }
From source file:MouseDragActionPanel.java
public void mouseDragged(MouseEvent evt) { int x = evt.getX(); int y = evt.getY(); if (currentSquareIndex >= 0) { Graphics g = getGraphics(); g.setXORMode(getBackground());/* ww w . j av a2 s. c o m*/ ((Graphics2D) g).draw(squares[currentSquareIndex]); squares[currentSquareIndex].x = x; squares[currentSquareIndex].y = y; ((Graphics2D) g).draw(squares[currentSquareIndex]); g.dispose(); } }
From source file:Main.java
public void mouseMoved(MouseEvent e) { if (!rectangle.contains(e.getX(), e.getY()) || e.isConsumed()) { if (isActive) { isActive = false;//from ww w . ja va2s .c om repaint(); } return; // quickly return, if outside our rectangle } int x = e.getX() - rectangle.x; int y = e.getY() - rectangle.y; boolean active = polygon.contains(x, y); if (isActive != active) setState(active); if (active) e.consume(); }
From source file:BufferedDraw.java
public void mouseReleased(MouseEvent e) { if (rect.contains(e.getX(), e.getY())) { updateLocation(e); } }
From source file:MouseDragActionPanel.java
public MouseDragActionPanel() { addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent evt) { int x = evt.getX(); int y = evt.getY(); currentSquareIndex = getSquare(x, y); if (currentSquareIndex < 0) // not inside a square add(x, y);// ww w.j a v a 2 s . c om } public void mouseClicked(MouseEvent evt) { int x = evt.getX(); int y = evt.getY(); if (evt.getClickCount() >= 2) { remove(currentSquareIndex); } } }); addMouseMotionListener(this); }
From source file:events.MouseMotionEventDemo.java
void eventOutput(String eventDescription, MouseEvent e) { textArea.append(eventDescription + " (" + e.getX() + "," + e.getY() + ")" + " detected on " + e.getComponent().getClass().getName() + NEWLINE); textArea.setCaretPosition(textArea.getDocument().getLength()); }