private int x=0;
private int y=0;
public ClickTest(){
setBounds(300,300,300,300);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addMouseListener(this);
}
public void mouseClicked(MouseEvent e) {
x = e.getX()-3;
y = e.getY()-3;
repaint();
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void paint(Graphics g){
super.paint(g);
g.setColor(Color.GREEN);
g.fillRect(x, y, 6, 6);
}
public static void main(String[] args) {
new ClickTest();
}
}