public class SwingPaintTest extends JFrame {
private SwingPaintTest() {
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.addMouseMotionListener(new MouseAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
super.mouseMoved(e);
paintPoint(e.getX(), e.getY());
}
});
}
public static void main(String args[]) {
SwingPaintTest paintTest = new SwingPaintTest();
paintTest.setSize(500, 500);
paintTest.setLocationRelativeTo(null);
paintTest.setVisible(true);
}
private void paintPoint(int x, int y) {
this.repaint(x, y, 1, 1);
}
@Override
public void paint(Graphics g) {
super.paint(g);
Rectangle rectangle = g.getClipBounds();
int i
= (int)rectangle.getX();
int j = (int)rectangle.getY();
g.setColor(Color.black);
g.fillOval(i, j, 1, 1);
}
}