List of usage examples for java.awt.event MouseEvent getPoint
public Point getPoint()
From source file:Main.java
public Main() { setLayout(null);/*from w w w .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.getPoint()); event.translatePoint(20, 20); System.out.println(event.getPoint()); } }); }
From source file:MainClass.java
public void mousePressed(MouseEvent me) { p = me.getPoint(); repaint(); }
From source file:MainClass.java
public void mouseDragged(MouseEvent me) { p = me.getPoint(); repaint(); }
From source file:Main.java
Main() { shapes.add(new Ellipse2D.Double(10, 10, 20, 30)); MouseAdapter listener = new MouseAdapter() { @Override// w w w. j a v a 2s . co m public void mouseClicked(MouseEvent me) { mouse = me.getPoint(); drawImage(); } }; l.addMouseListener(listener); drawImage(); JOptionPane.showMessageDialog(null, l); }
From source file:Main.java
Point getScreenLocation(MouseEvent e) { Point cursor = e.getPoint(); Point target_location = this.target.getLocationOnScreen(); return new Point((int) (target_location.getX() + cursor.getX()), (int) (target_location.getY() + cursor.getY())); }
From source file:Main.java
public Main() { DefaultListModel<String> model = new DefaultListModel<>(); model.addElement("one"); model.addElement("two"); model.addElement("three"); model.addElement("four"); model.addElement("five"); model.addElement("six"); model.addElement("seven"); model.addElement("eight"); model.addElement("nine"); model.addElement("ten"); JList<String> list = new JList(model) { public String getToolTipText(MouseEvent e) { int row = locationToIndex(e.getPoint()); Object o = getModel().getElementAt(row); return o.toString(); }//from ww w.java2 s . c om public Point getToolTipLocation(MouseEvent e) { int row = locationToIndex(e.getPoint()); Rectangle r = getCellBounds(row, row); return new Point(r.width, r.y); } }; JScrollPane scrollPane = new JScrollPane(list); getContentPane().add(scrollPane); }
From source file:Main.java
public Point getClick() { EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); while (true) { try {/*from w w w . j av a 2 s . c om*/ AWTEvent evt = eq.getNextEvent(); if (evt.getID() == MouseEvent.MOUSE_PRESSED) { MouseEvent mevt = (MouseEvent) evt; Point p = mevt.getPoint(); Point top = getRootPane().getLocation(); p.x -= top.x; p.y -= top.y; return p; } } catch (InterruptedException e) { } } }
From source file:Main.java
public Point getClick() { EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); System.out.println(eq.isDispatchThread()); while (true) { try {//from w w w .j a v a 2 s . c o m AWTEvent evt = eq.getNextEvent(); if (evt.getID() == MouseEvent.MOUSE_PRESSED) { MouseEvent mevt = (MouseEvent) evt; Point p = mevt.getPoint(); Point top = getRootPane().getLocation(); p.x -= top.x; p.y -= top.y; return p; } } catch (InterruptedException e) { } } }
From source file:Main.java
ScreenCaptureRectangle(final BufferedImage screen) { BufferedImage screenCopy = new BufferedImage(screen.getWidth(), screen.getHeight(), screen.getType()); JLabel screenLabel = new JLabel(new ImageIcon(screenCopy)); JScrollPane screenScroll = new JScrollPane(screenLabel); screenScroll.setPreferredSize(new Dimension(300, 300)); repaint(screen, screenCopy);//w w w .ja va 2s. c om screenLabel.repaint(); screenLabel.addMouseMotionListener(new MouseMotionAdapter() { Point start = new Point(); @Override public void mouseMoved(MouseEvent me) { start = me.getPoint(); repaint(screen, screenCopy); screenLabel.repaint(); } @Override public void mouseDragged(MouseEvent me) { Point end = me.getPoint(); captureRect = new Rectangle(start, new Dimension(end.x - start.x, end.y - start.y)); repaint(screen, screenCopy); screenLabel.repaint(); } }); JOptionPane.showMessageDialog(null, screenScroll); }
From source file:Main.java
public Point getClick() { EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); while (true) { try {// w ww. j a v a 2s .c o m AWTEvent pEvent = eq.peekEvent(); AWTEvent evt = eq.getNextEvent(); if (evt.getID() == MouseEvent.MOUSE_PRESSED) { MouseEvent mevt = (MouseEvent) evt; Point p = mevt.getPoint(); Point top = getRootPane().getLocation(); p.x -= top.x; p.y -= top.y; return p; } } catch (InterruptedException e) { } } }