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]
# 1

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());

}

}

BigDaddyLoveHandlesa at 2007-7-29 16:13:23 > top of Java-index,Java Essentials,Java Programming...
# 2

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

noobs_will_rulea at 2007-7-29 16:13:23 > top of Java-index,Java Essentials,Java Programming...
# 3

ohh actually just as i replied to the first post there was a reply from bigdaddy

our forum is so active

cheers

noobs_will_rulea at 2007-7-29 16:13:23 > top of Java-index,Java Essentials,Java Programming...
# 4

Wow! I love this forum lol ty for the help guys :)

Well.. now to continue on my game :)

Pizza_Piea at 2007-7-29 16:13:23 > top of Java-index,Java Essentials,Java Programming...
# 5

u love it then award dukes ;)

noobs_will_rulea at 2007-7-29 16:13:23 > top of Java-index,Java Essentials,Java Programming...
# 6

How exactly do I award dukes?

Pizza_Piea at 2007-7-29 16:13:23 > top of Java-index,Java Essentials,Java Programming...