1 21 22 27 28 package com.sun.activation.viewers; 29 30 import java.awt.*; 31 32 public class ImageViewerCanvas extends Canvas 33 { 34 private Image canvas_image = null; 35 36 39 public ImageViewerCanvas() 40 { 41 42 } 43 44 47 public void setImage(Image new_image) 48 { 49 canvas_image = new_image; 50 this.invalidate(); 51 this.repaint(); 52 } 53 54 57 public Dimension getPreferredSize() 58 { 59 Dimension d = null; 60 61 if(canvas_image == null) 62 { 63 d = new Dimension(200, 200); 64 } 65 else 66 d = new Dimension(canvas_image.getWidth(this), 67 canvas_image.getHeight(this)); 68 69 return d; 70 } 71 74 public void paint(Graphics g) 75 { 76 77 if(canvas_image != null) 78 g.drawImage(canvas_image, 0, 0, this); 79 80 } 81 82 } 83 | Popular Tags |