KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > piratepete > dbpirate > ui > SplashScreen


1 package com.piratepete.dbpirate.ui;
2
3 import java.awt.*;
4
5 /**
6  * SplashScreen Class
7  * Copyright (C) 2003 David L. Whitehurst<p>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.<p>
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.<p>
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<p>
22  *
23  * <a HREF="http://www.piratepetesoftware.com">piratepetesoftware.com</a><br>
24  * <a HREF="mailto:dlwhitehurst@comcast.net">dlwhitehurst@comcast.net</a>
25  *
26  * @version 1.1.0
27  */

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 JavaDoc 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         // wait for it to be painted to ensure progress is updated
82
// continuously
83
try
84         {
85             wait();
86         }
87         catch(InterruptedException JavaDoc 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         // XXX: This should not be hardcoded
115
//offscreenGfx.setColor(new Color(168,173,189));
116
//offscreenGfx.setColor(new Color(153,153,255));
117
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         //offscreenGfx.setColor(Color.black);
123

124         //String str = "Trial Version 1.1.0";
125

126         //offscreenGfx.drawString(str,
127
// (getWidth() - fm.stringWidth(str)) / 2,
128
// image.getHeight(this)+1 - fm.getDescent() - 10);
129

130         g.drawImage(offscreenImg,0,0,this);
131
132         notify();
133     }
134
135     // private members
136
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