You are using the old AWT Canvas
class as the base component. This class follows the AWT painting mechanism, where there is no paintComponent
method and you were supposed to override paint
to do custom graphics.
Change the base class to JComponent
and you can use the newer painting mechanism:
...
import javax.swing.JComponent;
public class GameCanvas extends JComponent {
This article compares how painting works in AWT and Swing if you want to know more about them.