1 package junit.swingui; 2 3 import java.awt.Font ; 4 import java.awt.GridBagConstraints ; 5 import java.awt.GridBagLayout ; 6 import java.awt.Insets ; 7 import java.awt.event.ActionEvent ; 8 import java.awt.event.ActionListener ; 9 import java.awt.event.WindowAdapter ; 10 import java.awt.event.WindowEvent ; 11 12 import javax.swing.Icon ; 13 import javax.swing.JButton ; 14 import javax.swing.JDialog ; 15 import javax.swing.JFrame ; 16 import javax.swing.JLabel ; 17 18 import junit.runner.BaseTestRunner; 19 import junit.runner.Version; 20 21 24 class AboutDialog extends JDialog { 25 public AboutDialog(JFrame parent) { 26 super(parent, true); 27 28 setResizable(false); 29 getContentPane().setLayout(new GridBagLayout ()); 30 setSize(330, 138); 31 setTitle("About"); 32 try { 34 setLocationRelativeTo(parent); 35 } catch (NoSuchMethodError e) { 36 TestSelector.centerWindow(this); 37 } 38 39 JButton close= new JButton ("Close"); 40 close.addActionListener( 41 new ActionListener () { 42 public void actionPerformed(ActionEvent e) { 43 dispose(); 44 } 45 } 46 ); 47 getRootPane().setDefaultButton(close); 48 JLabel label1= new JLabel ("JUnit"); 49 label1.setFont(new Font ("dialog", Font.PLAIN, 36)); 50 51 JLabel label2= new JLabel ("JUnit "+Version.id()+" by Kent Beck and Erich Gamma"); 52 label2.setFont(new Font ("dialog", Font.PLAIN, 14)); 53 54 JLabel logo= createLogo(); 55 56 GridBagConstraints constraintsLabel1= new GridBagConstraints (); 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 constraintsLabel2= new GridBagConstraints (); 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 constraintsButton1= new GridBagConstraints (); 69 constraintsButton1.gridx = 2; constraintsButton1.gridy = 2; 70 constraintsButton1.gridwidth = 2; constraintsButton1.gridheight = 1; 71 constraintsButton1.anchor = GridBagConstraints.CENTER; 72 constraintsButton1.insets= new Insets (8, 0, 8, 0); 73 getContentPane().add(close, constraintsButton1); 74 75 GridBagConstraints constraintsLogo1= new GridBagConstraints (); 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 () { 83 public void windowClosing(WindowEvent e) { 84 dispose(); 85 } 86 } 87 ); 88 } 89 protected JLabel createLogo() { 90 Icon icon= TestRunner.getIconResource(BaseTestRunner.class, "logo.gif"); 91 return new JLabel (icon); 92 } 93 } | Popular Tags |