its supposed to draw an oval on MouseClicked:
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class PaintPad extends JPanel implements MouseListener {
private int mouseX, mouseY;
public static void main(String args[]) {
PaintPad pad = new PaintPad();
pad.setGui();
}
public void setGui() {
JFrame frame = new JFrame();
JPanel drawP = new JPanel();
drawP.addMouseListener(this);
frame.getContentPane().add(BorderLayout.CENTER, drawP);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 500);
frame.setVisible(true);
}
public void paintComponent(Graphics g) {
g.fillOval(mouseX, mouseY, 10, 10);
}
public void mouseClicked(MouseEvent e) {
mouseX = e.getX();
mouseY = e.getY();
repaint();
}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
}
works but doesnt do anything. how to fix this?