I have created a small rectangle in a canvas which is on a JFrame. I have made the class a singleton (I know some of you will say it's bad practice, but i'm fine with that). I am currently just using the repaint() method whenever an arrow key is pressed. However, I am now looking at making a Game loop with a swing timer.
I have created a class called "GameLoop.java" and added the following code.
public class GameLoop implements ActionListener {
Timer timer = new Timer(10, this);
public void actionPerformed(ActionEvent e) {
timer.start();
GameCanvas.getInstance().repaint();
}
}
This however, does nothing to the screen when an arrow is pressed. Is there something I am missing / doing wrong?