KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > corbaclient > SplashScreen


1 package org.enhydra.shark.corbaclient;
2
3 import java.awt.*;
4 import java.awt.event.*;
5
6 import javax.swing.*;
7
8 /**
9  * Used to view some kind of splash screen.
10  *
11  * @author Sasa Bojanic
12  * @version 1.0
13  */

14 public class SplashScreen extends JWindow {
15
16    JLabel splashI=new JLabel();
17    JLabel splashM=new JLabel();
18    JLabel splashT=new JLabel();
19    JPanel p=new JPanel();
20    public SplashScreen (Window parent) {
21       super(parent);
22
23       getContentPane().add(p,BorderLayout.CENTER);
24       splashI.setLayout(new BorderLayout());
25       splashI.add(splashT, BorderLayout.NORTH);
26       splashI.add(splashM, BorderLayout.CENTER);
27       splashI.setBorder(BorderFactory.createRaisedBevelBorder());
28       p.add(splashI);
29    }
30
31    public void show (String JavaDoc splashIcon,String JavaDoc splashTitle,String JavaDoc splashMessage) {
32       String JavaDoc pre="<html><font size=4 face=\"sans-serif\" color=\"blue\">";
33       String JavaDoc post="</font></html>";
34       if (splashTitle==null) splashTitle="";
35       if (splashMessage==null) splashMessage="";
36       int pw=getPreferredWidth(splashTitle,splashMessage);
37       splashTitle=pre+splashTitle+post;
38       pre="<html><font size=4 face=\"sans-serif\" color=\"red\">";
39       splashMessage=pre+splashMessage+post;
40
41       try {
42          splashI.setIcon(new ImageIcon(ResourceManager.getResource(splashIcon)));
43       } catch (Exception JavaDoc ex) {}
44       splashT.setText(splashTitle);
45       splashT.setHorizontalAlignment(JLabel.CENTER);
46       splashM.setText(splashMessage);
47       splashM.setHorizontalAlignment(JLabel.CENTER);
48       try {
49          if (pw>600) pw=600;
50          splashI.setPreferredSize(new Dimension(pw,
51                (int)((3+pw/600)*getFontMetrics(getFont()).getHeight()*1.5)));
52          pack();
53          Utils.center(this);
54          setVisible(true);
55          p.paintImmediately(p.getBounds());
56       } catch (Exception JavaDoc ex) {
57          setVisible(false);
58       }
59
60    }
61
62    protected int getPreferredWidth (String JavaDoc s1,String JavaDoc s2) {
63       int w1=getFontMetrics(getFont()).stringWidth(s1);
64       int w2=getFontMetrics(getFont()).stringWidth(s2);
65
66       if (w1>w2) {
67          return w1+50;
68       } else {
69          return w2+50;
70       }
71    }
72
73 }
74
75
Popular Tags