Sie sind auf Seite 1von 2

UnitTest.

java

1 package main;
2
3 import java.awt.event.ActionEvent;
4 import java.awt.event.ActionListener;
5
6 import javax.swing.ButtonGroup;
7 import javax.swing.JButton;
8 import javax.swing.JComboBox;
9 import javax.swing.JFrame;
10 import javax.swing.JLabel;
11 import javax.swing.JOptionPane;
12 import javax.swing.JPanel;
13 import javax.swing.JRadioButton;
14 import javax.swing.JTextField;
15
16 public class UnitTest {
17
18 public static void main(String[] args) {
19
20 JFrame mainFrame = new JFrame("Unit Test");
21 JPanel jp = new JPanel();
22 jp.setLayout(null);
23 mainFrame.setContentPane(jp);
24
25 JLabel lblFirstName = new JLabel("First Name: ");
26 JLabel lblGender = new JLabel("Gender: ");
27 JTextField txtFirstName = new JTextField();
28 JButton btnSubmit = new JButton("Submit");
29
30 JRadioButton rbMale = new JRadioButton("Male");
31 JRadioButton rbFemale = new JRadioButton("Female");
32 ButtonGroup bgGender = new ButtonGroup();
33 bgGender.add(rbMale);
34 bgGender.add(rbFemale);
35
36 JLabel lblSection = new JLabel("Section: ");
37
38 String section[] = {"ICT11‐01", "ICT11‐02", "ICT11‐03", "ICT11‐04", "ICT11‐05", 
"ICT11‐06"};
39 JComboBox cbSection = new JComboBox(section);
40
41 lblFirstName.setBounds(10, 20, 100, 40);
42 txtFirstName.setBounds(120, 20, 100, 40);
43 btnSubmit.setBounds(120, 80, 100, 40);
44 lblGender.setBounds(10, 150, 100, 40);
45 rbMale.setBounds(120, 150, 100, 40);
46 rbFemale.setBounds(120, 190, 100, 40);
47 lblSection.setBounds(10, 240, 100, 40);
48 cbSection.setBounds(120, 240, 100, 40);
49
50 btnSubmit.addActionListener(new ActionListener() {
51 @Override
52 public void actionPerformed(ActionEvent arg0) {
53 // TODO Auto‐generated method stub
54 JOptionPane.showMessageDialog(null, "You are so cute", "FYI", 
JOptionPane.INFORMATION_MESSAGE);
55 }
56 });
57
58 jp.add(lblFirstName);
59 jp.add(txtFirstName);

Page 1
UnitTest.java

60 jp.add(btnSubmit);
61 jp.add(rbMale);
62 jp.add(rbFemale);
63 jp.add(lblGender);
64 jp.add(lblSection);
65 jp.add(cbSection);
66
67 mainFrame.setVisible(true);
68 mainFrame.setSize(500, 500);
69 mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
70
71 }
72
73 }
74
75
76
77

Page 2

Das könnte Ihnen auch gefallen