KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junit > awtui > Logo


1 package junit.awtui;
2
3 import java.awt.Canvas JavaDoc;
4 import java.awt.Graphics JavaDoc;
5 import java.awt.Image JavaDoc;
6 import java.awt.MediaTracker JavaDoc;
7 import java.awt.SystemColor JavaDoc;
8 import java.awt.Toolkit JavaDoc;
9 import java.awt.image.ImageProducer JavaDoc;
10 import java.net.URL JavaDoc;
11
12 import junit.runner.BaseTestRunner;
13
14 public class Logo extends Canvas JavaDoc {
15     private Image JavaDoc fImage;
16     private int fWidth;
17     private int fHeight;
18     
19     public Logo() {
20         fImage= loadImage("logo.gif");
21         MediaTracker JavaDoc tracker= new MediaTracker JavaDoc(this);
22         tracker.addImage(fImage, 0);
23         try {
24             tracker.waitForAll();
25         } catch (Exception JavaDoc e) {
26         }
27
28         if (fImage != null) {
29             fWidth= fImage.getWidth(this);
30             fHeight= fImage.getHeight(this);
31         } else {
32             fWidth= 20;
33             fHeight= 20;
34         }
35         setSize(fWidth, fHeight);
36     }
37     
38     public Image JavaDoc loadImage(String JavaDoc name) {
39         Toolkit JavaDoc toolkit= Toolkit.getDefaultToolkit();
40         try {
41             URL JavaDoc url= BaseTestRunner.class.getResource(name);
42             return toolkit.createImage((ImageProducer JavaDoc) url.getContent());
43         } catch (Exception JavaDoc ex) {
44         }
45         return null;
46     }
47     
48     public void paint(Graphics JavaDoc g) {
49         paintBackground(g);
50         if (fImage != null)
51             g.drawImage(fImage, 0, 0, fWidth, fHeight, this);
52     }
53     
54     public void paintBackground( java.awt.Graphics JavaDoc g) {
55         g.setColor(SystemColor.control);
56         g.fillRect(0, 0, getBounds().width, getBounds().height);
57     }
58 }
Popular Tags