I\'m trying to draw an image on an AWT Canvas.
The only line I\'ve got this far is:
Canvas canvas = new Canvas();
I\'m not sure which m
You have several ways to do this. If you don't want to create a subclass of Canvas
, add this line (where img
is a subclass java.awt.Image
):
canvas.getGraphics().drawImage(img, 0,0, null);
This will draw your Image to position 0,0 on the Canvas. If you create a subclass of canvas, overwrite the paint
-Method:
public void paint (Graphics g) {
g.drawImage(img, 0,0, null);
}