I've made a simple program where you should be able to hold and drag the mouse to paint something. Now, this program works fine on my Windows, but when I try the exact same code on my Mac, the 10x10 dot I'm trying to draw with just follows the cursor, but doesn't leave a track behind it.
First, I thought it was a problem with the JDK, so I've reinstalled and installed different versions. Same with both Eclipse And Netbeans, reinstalled multiple times, but it did not work.
public class panelDraw extends JPanel {
int x, y;
/**
* Create the panel.
*/
public panelDraw() {
addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
x = e.getX();
y = e.getY();
repaint();
}
});
}
public void paintComponent(Graphics g) {
g.fillRect(x, y, 10, 10);
}
Here is the panel that I then put in a JFrame to run the program. As I said, no problem on my Windows, but on the Mac, it doesn't "draw" anything the dot just follows the cursor.
Thank you for the help!