Coordinate « Event « Java Swing Q&A





1. The coordinate of mouse?    stackoverflow.com

public class mouse extends JFrame {
    private int x, y;
    private JLabel label;

    public mouse() {
       ...

2. mouse click event for 3D coordinates in java    coderanch.com

when i use mouse click event in java i can catch the x coordinate and the y coordinate of the point clicked by using event.getX() and event.getY(). But when similarly i use event.getZ(),it is giving error. i desperately need the Z coordinate also to be read as iam working on OPENGL and java and developing a graphics tool for which this ...

3. Getting Relative Mouse Coordinates    coderanch.com

import java.awt.*; import java.awt.event.*; import javax.swing.*; public class MouseTest { JLabel label; JPanel child; public void setText(int x, int y) { String s = ""; if(x > 0 && y > 0) s = "x = " + x + " y = " + y; label.setText(s); } private JPanel getContent() { label = new JLabel(); label.setHorizontalAlignment(JLabel.CENTER); GridBagLayout gridbag = new ...

4. Wanted: example mouse coordinates->world coordinates    coderanch.com

import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Conversion { JLabel panelX, panelY, convertedX, convertedY; private JScrollPane getCenter(final Component c) { JPanel panel = new JPanel(); panel.setPreferredSize(new Dimension(500,500)); panel.addMouseMotionListener(new MouseMotionAdapter() { public void mouseMoved(MouseEvent e) { Point p = e.getPoint(); panelX.setText(String.valueOf(p.x)); panelY.setText(String.valueOf(p.y)); Point dest = SwingUtilities.convertPoint(e.getComponent(), p, c); convertedX.setText(String.valueOf(dest.x)); convertedY.setText(String.valueOf(dest.y)); } }); return new JScrollPane(panel); } private JPanel getLabels() { panelX ...

5. click the mouse in a coordinate    coderanch.com