import java.awt.*; public class DrawingArea extends Panel { public Image offimage; Graphics offgraphics; Dimension offdimension; int offsetx, offsety; ImagePalette ip; public DrawingArea(ImagePalette ip) { this.ip = ip; } public void paint(Graphics g) { Dimension d = size(); int dim; if (offgraphics == null) { setBackground(Color.black); setForeground(Color.black); offimage = createImage(d.width, d.height); offgraphics = offimage.getGraphics(); offdimension = d; System.out.println("Initialized drawing area..."); } else if ((offdimension.width != d.width) || (offdimension.height != d.height)) { System.out.println("Resized drawing area..."); offdimension = d; Image resizedimage = createImage(d.width, d.height); offgraphics = resizedimage.getGraphics(); offimage = offimage.getScaledInstance(d.width, d.height, offimage.SCALE_SMOOTH); MediaTracker mt = new MediaTracker(this); mt.addImage(offimage, 7); try{ mt.waitForID(7); } catch (Exception e){ System.out.println(e); } offgraphics.drawImage(offimage, 0, 0, this); offimage = resizedimage; } g.drawImage(offimage, 0, 0, this); } public void update(Graphics g){ paint(g); } private void brush(int x, int y) { offgraphics.drawImage(ip.brush, x - (ip.brush.getWidth(this)/2), y - (ip.brush.getHeight(this)/2), this); repaint(); } public boolean mouseDown(Event e, int x, int y) { brush(x, y); return true; } public boolean mouseDrag(Event e, int x, int y) { brush(x, y); return true; } }