package awb; import java.awt.*; /* PictureCanvas Class * Eric Jewart * * This class is a Canvas so it can be used * as a component in any Java app. It holds * a Picture object. Double-clicking on the * PictureCanvas will spawn an ImageViewer. */ public class PictureCanvas extends Canvas { private int WIDTH, HEIGHT; private Picture myPicture; private String myTitle; public PictureCanvas(int w, int h) { WIDTH = w; HEIGHT = h; } public Dimension preferredSize() { return new Dimension(WIDTH,HEIGHT); } public Dimension minimumSize() { return new Dimension(WIDTH,HEIGHT); } public void paint(Graphics g) { if (myPicture != null) myPicture.draw(g,0,0,this); } public Picture getPicture() { return myPicture; } public void setPicture(Picture p, String t) { myPicture = p; myTitle = t; repaint(); } public void clear() { myPicture = null; repaint(); } public boolean handleEvent(Event e) { if ((e.id == Event.MOUSE_DOWN) && (e.clickCount == 2)) { ImageViewer iv = new ImageViewer(myPicture, myTitle); return true; } return super.handleEvent(e); } }