1 package com.piratepete.dbpirate.ui; 2 3 import java.awt.*; 4 5 28 29 30 public class SplashScreen extends Canvas 31 { 32 public int left; 33 public SplashScreen() 34 { 35 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 36 setBackground(Color.white); 37 38 Font font = new Font("Arial",Font.BOLD,10); 39 setFont(font); 40 fm = getFontMetrics(font); 41 42 image = getToolkit().getImage(getClass().getResource("/com/piratepete/dbpirate/ui/images/splash.png")); 43 MediaTracker tracker = new MediaTracker(this); 44 tracker.addImage(image,0); 45 46 try 47 { 48 tracker.waitForAll(); 49 } 50 catch(Exception e) 51 { 52 e.printStackTrace(); 53 } 54 55 win = new Window(new Frame()); 56 57 Dimension screen = getToolkit().getScreenSize(); 58 Dimension size = new Dimension(image.getWidth(this) + 2, 59 image.getHeight(this) + 2 + PROGRESS_HEIGHT); 60 win.setSize(size); 61 62 win.setLayout(new BorderLayout()); 63 win.add(BorderLayout.CENTER,this); 64 win.setLocation((screen.width - size.width) / 2, 65 (screen.height - size.height) / 2); 66 win.validate(); 67 win.show(); 68 69 } 70 71 public void dispose() 72 { 73 win.dispose(); 74 } 75 76 public synchronized void advance() 77 { 78 progress++; 79 repaint(); 80 81 try 84 { 85 wait(); 86 } 87 catch(InterruptedException ie) 88 { 89 ie.printStackTrace(); 90 } 91 } 92 93 public void update(Graphics g) 94 { 95 paint(g); 96 } 97 98 public synchronized void paint(Graphics g) 99 { 100 Dimension size = getSize(); 101 102 if(offscreenImg == null) 103 { 104 offscreenImg = createImage(size.width,size.height); 105 offscreenGfx = offscreenImg.getGraphics(); 106 offscreenGfx.setFont(getFont()); 107 } 108 109 offscreenGfx.setColor(Color.blue); 110 offscreenGfx.drawRect(0,0,size.width - 1,size.height - 1); 111 112 offscreenGfx.drawImage(image,1,1,this); 113 114 offscreenGfx.setColor(new Color(36,28,127)); 118 119 offscreenGfx.fillRect(1,image.getHeight(this) + 1, 120 ((win.getWidth() - 2) * progress) / 6,PROGRESS_HEIGHT); 121 122 124 126 130 g.drawImage(offscreenImg,0,0,this); 131 132 notify(); 133 } 134 135 private FontMetrics fm; 137 private Window win; 138 private Image image; 139 private Image offscreenImg; 140 private Graphics offscreenGfx; 141 private int progress; 142 private static final int PROGRESS_HEIGHT = 20; 143 } 144 | Popular Tags |