I created a MouseMotionListener to detect when then mouse moves over a menu item. I noticed that the getX() and getY() are off a little bit. It seems like the Y is off by 20pixels or so, and the X is off by about 5-6. Here is my mouse code:
import java.awt.event.MouseMotionListener; import java.awt.event.MouseEvent; public class mouseMotion implements MouseMotionListener { public void mouseMoved(MouseEvent e){ if (e.getX() >= 608 && e.getX() <= 640 && e.getY() <= 32) { System.out.println("test"); } } public void mouseDragged(MouseEvent e){} }
The image is 32x32pixels and is painted at (608,0), Which is why I assumed that I should check if the mouse is in (608-640,0-32)
I set my JFrame's size with the following code to prevent this bug, but it seems that it's back...
f.getContentPane().setPreferredSize(new Dimension(640,480)); f.add(gui); f.addKeyListener(kb); f.addMouseListener(m1); f.addMouseMotionListener(m2); f.pack(); f.setVisible(true);