Suggestions:
- Don’t use Canvas as you shouldn’t mix AWT with Swing components unnecessarily.
- Instead use a JPanel or JComponent.
- Don’t get your Graphics object by calling
getGraphics()
on a component as the Graphics object obtained will be transient. - Draw in the JPanel’s
paintComponent()
method. - All this is well explained in several tutorials that are easily found. Why not read them first before trying to guess at this stuff?
Key tutorial links:
- Basic Tutorial: Lesson: Performing Custom Painting
- More advanced information: Painting in AWT and Swing