I wanted to make a 2D game. I started making the drawing class, but I came across a problem: the ActionListener
wouldn't work. It wouldn't draw or output my message to say it was working. Here is the code:
public class Drawing extends JPanel implements ActionListener {
private int count = 0;
public void actionPerformed(ActionEvent e) {
count++;
repaint();
}
@Override
protected void paintComponent(Graphics g) {
System.out.println("Hi");
g.setColor(Color.black);
g.clearRect(0, 0, Boot.WIDTH, Boot.HEIGHT);
g.fillRect(0, 0, Boot.WIDTH, Boot.HEIGHT);
g.setColor(Color.white);
g.drawString("Path count: " + count, 50, 50);
}
}
I would assume this would work, as I used this way of drawing in other projects. What would be causing this?