1 package junit.awtui; 2 3 import java.awt.Canvas ; 4 import java.awt.Graphics ; 5 import java.awt.Image ; 6 import java.awt.MediaTracker ; 7 import java.awt.SystemColor ; 8 import java.awt.Toolkit ; 9 import java.awt.image.ImageProducer ; 10 import java.net.URL ; 11 12 import junit.runner.BaseTestRunner; 13 14 public class Logo extends Canvas { 15 private Image fImage; 16 private int fWidth; 17 private int fHeight; 18 19 public Logo() { 20 fImage= loadImage("logo.gif"); 21 MediaTracker tracker= new MediaTracker (this); 22 tracker.addImage(fImage, 0); 23 try { 24 tracker.waitForAll(); 25 } catch (Exception 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 loadImage(String name) { 39 Toolkit toolkit= Toolkit.getDefaultToolkit(); 40 try { 41 URL url= BaseTestRunner.class.getResource(name); 42 return toolkit.createImage((ImageProducer ) url.getContent()); 43 } catch (Exception ex) { 44 } 45 return null; 46 } 47 48 public void paint(Graphics 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 g) { 55 g.setColor(SystemColor.control); 56 g.fillRect(0, 0, getBounds().width, getBounds().height); 57 } 58 } | Popular Tags |