List of usage examples for java.awt.event MouseEvent getX
public int getX()
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;/*from w ww .j a v a2s .co m*/ } 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:MouseDragActionPanel.java
public void mouseDragged(MouseEvent evt) { int x = evt.getX(); int y = evt.getY(); if (currentSquareIndex >= 0) { Graphics g = getGraphics(); g.setXORMode(getBackground());//from w w w. jav a 2 s . com ((Graphics2D) g).draw(squares[currentSquareIndex]); squares[currentSquareIndex].x = x; squares[currentSquareIndex].y = y; ((Graphics2D) g).draw(squares[currentSquareIndex]); g.dispose(); } }
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:painting.SwingPaintDemo3.java
public MyPanel() { setBorder(BorderFactory.createLineBorder(Color.black)); addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { moveSquare(e.getX(), e.getY()); }//from w w w . j a v a 2 s . c om }); 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 av a 2 s . 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 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);/* w w w . ja 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:Main.java
public void mouseMoved(MouseEvent e) { if (!rectangle.contains(e.getX(), e.getY()) || e.isConsumed()) { if (isActive) { isActive = false;//from w w w .j a v a2s.c o m 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: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()); }
From source file:BufferedDraw.java
public void mouseReleased(MouseEvent e) { if (rect.contains(e.getX(), e.getY())) { updateLocation(e); } }
From source file:BezLab.java
public void mouseReleased(MouseEvent e) { if (dragIndex == NOT_DRAGGING) return;//from w ww . ja va 2 s .c o m xs[dragIndex] = e.getX(); ys[dragIndex] = e.getY(); dragIndex = NOT_DRAGGING; repaint(); }