KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junit > swingui > AboutDialog


1 package junit.swingui;
2
3 import java.awt.Font JavaDoc;
4 import java.awt.GridBagConstraints JavaDoc;
5 import java.awt.GridBagLayout JavaDoc;
6 import java.awt.Insets JavaDoc;
7 import java.awt.event.ActionEvent JavaDoc;
8 import java.awt.event.ActionListener JavaDoc;
9 import java.awt.event.WindowAdapter JavaDoc;
10 import java.awt.event.WindowEvent JavaDoc;
11
12 import javax.swing.Icon JavaDoc;
13 import javax.swing.JButton JavaDoc;
14 import javax.swing.JDialog JavaDoc;
15 import javax.swing.JFrame JavaDoc;
16 import javax.swing.JLabel JavaDoc;
17
18 import junit.runner.BaseTestRunner;
19 import junit.runner.Version;
20
21 /**
22  * The AboutDialog.
23  */

24 class AboutDialog extends JDialog JavaDoc {
25     public AboutDialog(JFrame JavaDoc parent) {
26         super(parent, true);
27          
28         setResizable(false);
29         getContentPane().setLayout(new GridBagLayout JavaDoc());
30         setSize(330, 138);
31         setTitle("About");
32         // setLocationRelativeTo is only available in JDK 1.4
33
try {
34             setLocationRelativeTo(parent);
35         } catch (NoSuchMethodError JavaDoc e) {
36             TestSelector.centerWindow(this);
37         }
38
39         JButton JavaDoc close= new JButton JavaDoc("Close");
40         close.addActionListener(
41             new ActionListener JavaDoc() {
42                 public void actionPerformed(ActionEvent JavaDoc e) {
43                     dispose();
44                 }
45             }
46         );
47         getRootPane().setDefaultButton(close);
48         JLabel JavaDoc label1= new JLabel JavaDoc("JUnit");
49         label1.setFont(new Font JavaDoc("dialog", Font.PLAIN, 36));
50         
51         JLabel JavaDoc label2= new JLabel JavaDoc("JUnit "+Version.id()+" by Kent Beck and Erich Gamma");
52         label2.setFont(new Font JavaDoc("dialog", Font.PLAIN, 14));
53         
54         JLabel JavaDoc logo= createLogo();
55
56         GridBagConstraints JavaDoc constraintsLabel1= new GridBagConstraints JavaDoc();
57         constraintsLabel1.gridx = 3; constraintsLabel1.gridy = 0;
58         constraintsLabel1.gridwidth = 1; constraintsLabel1.gridheight = 1;
59         constraintsLabel1.anchor = GridBagConstraints.CENTER;
60         getContentPane().add(label1, constraintsLabel1);
61
62         GridBagConstraints JavaDoc constraintsLabel2= new GridBagConstraints JavaDoc();
63         constraintsLabel2.gridx = 2; constraintsLabel2.gridy = 1;
64         constraintsLabel2.gridwidth = 2; constraintsLabel2.gridheight = 1;
65         constraintsLabel2.anchor = GridBagConstraints.CENTER;
66         getContentPane().add(label2, constraintsLabel2);
67
68         GridBagConstraints JavaDoc constraintsButton1= new GridBagConstraints JavaDoc();
69         constraintsButton1.gridx = 2; constraintsButton1.gridy = 2;
70         constraintsButton1.gridwidth = 2; constraintsButton1.gridheight = 1;
71         constraintsButton1.anchor = GridBagConstraints.CENTER;
72         constraintsButton1.insets= new Insets JavaDoc(8, 0, 8, 0);
73         getContentPane().add(close, constraintsButton1);
74
75         GridBagConstraints JavaDoc constraintsLogo1= new GridBagConstraints JavaDoc();
76         constraintsLogo1.gridx = 2; constraintsLogo1.gridy = 0;
77         constraintsLogo1.gridwidth = 1; constraintsLogo1.gridheight = 1;
78         constraintsLogo1.anchor = GridBagConstraints.CENTER;
79         getContentPane().add(logo, constraintsLogo1);
80
81         addWindowListener(
82             new WindowAdapter JavaDoc() {
83                 public void windowClosing(WindowEvent JavaDoc e) {
84                     dispose();
85                 }
86             }
87         );
88     }
89     protected JLabel JavaDoc createLogo() {
90         Icon JavaDoc icon= TestRunner.getIconResource(BaseTestRunner.class, "logo.gif");
91         return new JLabel JavaDoc(icon);
92     }
93 }
Popular Tags