01: package demo.notification.whiteboard;
02:
03: import java.io.File;
04:
05: import java.awt.Canvas;
06:
07: import java.awt.Toolkit;
08:
09: import java.awt.MediaTracker;
10:
11: import java.awt.Dimension;
12:
13: import java.awt.Image;
14:
15: import java.awt.Graphics;
16:
17: // das im konstruktor u"bergebene bild laden
18:
19: // und darstellen ...
20:
21: public class PicView extends Canvas {
22:
23: private Toolkit toolkit;
24:
25: private MediaTracker mediaTracker;
26:
27: private Image image;
28:
29: public PicView(String filename) {
30:
31: super ();
32:
33: toolkit = Toolkit.getDefaultToolkit();
34:
35: mediaTracker = new MediaTracker(this );
36:
37: image = loadImage(filename);
38:
39: setSize(getDim());
40:
41: }
42:
43: private Dimension getDim() {
44:
45: Dimension d = new Dimension(0, 0);
46:
47: if (image != null) {
48:
49: d.width = image.getWidth(this );
50:
51: d.height = image.getHeight(this );
52:
53: }
54:
55: return d;
56:
57: }
58:
59: Image loadImage(String filename) {
60:
61: if (!new File(filename).exists()) {
62:
63: System.out.println("File " + filename + " not Found !");
64:
65: System.exit(1);
66:
67: }
68:
69: Image imageData = toolkit.getImage(filename);
70:
71: mediaTracker.addImage(imageData, 0);
72:
73: try {
74:
75: mediaTracker.waitForID(0);
76:
77: } catch (InterruptedException ie) {
78: }
79:
80: return imageData;
81:
82: }
83:
84: public void paint(Graphics g) {
85:
86: g.clearRect(0, 0, getDim().width, getDim().height);
87:
88: g.drawImage(image, 0, 0, null);
89:
90: }
91:
92: }
|