import java.awt.*; import java.awt.image.*; /* ======================================================== Coordinate system of a Canvas: 0 1 col# +----+--------+----------+ | | ^ 1 | | | | | | | | | height row# | (col#,row#) | | | | | | | | +------------------------+ v <----------------------> width Coordinate = (col#, row#) ======================================================== */ public class MyCanvas extends Canvas { static int MAX_WIDTH = 400; static int MAX_HEIGHT = 300; // Dimensions of the 2-dim canvas /* ------------------------------------------------- This variable is the 2-dim. array of pixels (= image) used for the drawing ------------------------------------------------- */ static BufferedImage Image = new BufferedImage(MAX_WIDTH, MAX_HEIGHT, BufferedImage.TYPE_INT_RGB); /* ----------------------------------------- repaint will invoke paint() and will use "Image" ----------------------------------------- */ public void paint(Graphics g) { g.drawImage(Image, 0, 0, Color.white, null); } /* ----------------------------------------- Redefine update() will eliminate flicker ----------------------------------------- */ public void update(Graphics g) { paint(g); } }