Problem with java.awt.MouseInfo or java.awt.event.*;
I have a problem with the MouseInfo class. I think.. because in my mousePressed(MouseEvent event) method, I have this:
publicvoid mousePressed(MouseEvent event){
pInfo = mInfo.getPointerInfo();
point = pInfo.getLocation();
pointX = point.getX();
pointY = point.getY();
System.out.println("pointer is at: (" + (int)pointX +", " + (int)pointY +")");
}
I think you all could figure out what this does. I declared the variables at the top and I implemented MouseListener... when I click it doesnt tell me the X and Y coords.
Alright, thanks. Any help appreciated.
[884 byte] By [
Pizza_Piea] at [2007-11-27 11:26:56]

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MouseExample extends MouseAdapter implements Runnable {
@Override
public void mousePressed(MouseEvent event) {
int x = event.getX();
int y = event.getY();
System.out.println("x=" + x + ", y=" + y);
}
@Override
public void run() {
JLabel label = new JLabel("Click anywhere", SwingConstants.CENTER);
label.setPreferredSize(new Dimension(300, 200));
label.addMouseListener(this);
JFrame f = new JFrame();
f.getContentPane().add(label);
f.pack();
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
public static void main(String[] args) {
EventQueue.invokeLater(new MouseExample());
}
}
u see u have not used the object event anywhere
do like thispublic void mousePressed(MouseEvent event) {
//pInfo = mInfo.getPointerInfo();
//point = pInfo.getLocation();
pointX = event.getX();
pointY = eventgetY();}
cheers