KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > AboutDialog


1 /*
2  * SNMP Inquisitor
3  *
4  * Copyright (C) 2004, Jonathan Sevy <jsevy@mcs.drexel.edu>
5  *
6  * This is free software. Redistribution and use in source and binary forms, with
7  * or without modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice, this
11  * list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  * derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
21  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */

29
30
31
32 import java.awt.*;
33 import javax.swing.*;
34
35 public class AboutDialog extends JDialog
36                                 implements Runnable JavaDoc
37 {
38
39     private JLabel aboutLabel1 = new JLabel("SNMP Inquisitor");
40     private JLabel aboutLabel2 = new JLabel("J. Sevy");
41     private JLabel aboutLabel3 = new JLabel("November, 2000");
42     private JLabel aboutLabel4 = new JLabel("");
43     private JLabel aboutLabel5 = new JLabel("");
44     
45     private String JavaDoc inquisitionString = "\"NO one expects the SNMP Inquisition...\" ";
46     private String JavaDoc mpString = " (- shamelessly adapted from Monty Python's Flying Circus)";
47     
48     Thread JavaDoc displayThread;
49     
50     
51     public AboutDialog(JFrame parent)
52     {
53         super(parent, "About SNMP Inquisitor", true /*modal*/);
54         
55         this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
56         
57         setUpDisplay();
58         
59         this.setLocation(Math.round((parent.getSize().width - this.getSize().width)/2), Math.round((parent.getSize().height - this.getSize().height)/2));
60         
61         // create and start display thread
62
displayThread = new Thread JavaDoc(this);
63         displayThread.start();
64         
65         this.show();
66     
67     }
68     
69     
70     
71     
72     public void hide()
73     {
74         super.hide();
75         
76         // interrupt thread so it can exit..
77
displayThread.interrupt();
78     }
79     
80     
81         
82         
83     private void setUpDisplay()
84     {
85         
86         // set params for layout manager
87
GridBagLayout theLayout = new GridBagLayout();
88         GridBagConstraints c = new GridBagConstraints();
89         
90         c.gridwidth = 1;
91         c.gridheight = 1;
92         c.fill = GridBagConstraints.NONE;
93         c.ipadx = 0;
94         c.ipady = 0;
95         c.insets = new Insets(2,2,2,2);
96         c.anchor = GridBagConstraints.CENTER;
97         c.weightx = 0;
98         c.weighty = 0;
99         
100         JPanel aboutPanel = new JPanel();
101         aboutPanel.setLayout(theLayout);
102         
103         c.gridx = 1;
104         c.gridy = 1;
105         theLayout.setConstraints(aboutLabel1, c);
106         aboutPanel.add(aboutLabel1);
107         
108         c.gridx = 1;
109         c.gridy = 2;
110         theLayout.setConstraints(aboutLabel2, c);
111         aboutPanel.add(aboutLabel2);
112         
113         c.gridx = 1;
114         c.gridy = 3;
115         theLayout.setConstraints(aboutLabel3, c);
116         aboutPanel.add(aboutLabel3);
117         
118         c.gridx = 1;
119         c.gridy = 4;
120         theLayout.setConstraints(aboutLabel4, c);
121         aboutPanel.add(aboutLabel4);
122         
123         c.gridx = 1;
124         c.gridy = 5;
125         theLayout.setConstraints(aboutLabel5, c);
126         aboutPanel.add(aboutLabel5);
127         
128         
129         this.getContentPane().add(aboutPanel);
130         this.pack();
131         
132         this.setSize(300, 150);
133         
134     }
135     
136     
137     
138     public void run()
139     {
140         
141         
142         try
143         {
144             
145             
146             // play sound clip from jar file, IF java version high enough...
147

148             String JavaDoc version = System.getProperty("java.version");
149             
150             //System.out.println(version);
151
//System.out.println(version.compareTo("1.3"));
152

153             if (version.compareTo("1.3") >= 0)
154             {
155                 AudioFilePlayer audioPlayer = new AudioFilePlayer("SNMPInquisitor.jar", "inquisition.wav");
156                 audioPlayer.playFromJarFile();
157             }
158             
159             // simultaneously, write message out a character at a time...
160
int numChars = inquisitionString.length();
161             
162             for (int i = 0; i < numChars; i++)
163             {
164                 aboutLabel4.setText(inquisitionString.substring(0,i));
165                 Thread.sleep(60);
166             }
167             
168             aboutLabel5.setText(mpString);
169             
170     
171         }
172         catch(Exception JavaDoc e)
173         {
174             // don't bother informing of exception; just exit...
175
//System.out.println(e);
176
}
177             
178         
179         // later!
180
}
181             
182             
183             
184 }
Popular Tags