-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentRegistration.java
More file actions
221 lines (161 loc) · 6.57 KB
/
Copy pathStudentRegistration.java
File metadata and controls
221 lines (161 loc) · 6.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package javaapplication448;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JProgressBar;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSlider;
import javax.swing.JSpinner;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SpinnerNumberModel;
/**
*
* @author DELL
*/
public class StudentRegistration extends JFrame {
private JTextField txtName;
private JPasswordField txtPassword;
private JRadioButton rdoMale, rdoFemale;
private ButtonGroup genderGroup;
private JCheckBox chkSoccer, chkReading,chkSinging,chkDancing;
private JComboBox<String> cmbProvince;
private JTextArea txtComments;
private JScrollPane scrollPane;
private JButton btnChooseFile, btnRegister;
private JFileChooser fileChooser;
private JSpinner spnAge;
private JSlider sldSatisfaction;
private JProgressBar progressBar;
private JMenuBar menuBar;
private JMenu menuFile, menuHelp;
private JMenuItem mnuExit, mnuAbout;
public StudentRegistration() {
setTitle("Student Registration System");
setSize(600, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
// ===== MENU =====
menuBar = new JMenuBar();
menuFile = new JMenu("File");
menuHelp = new JMenu("Help");
mnuExit = new JMenuItem("Exit");
mnuAbout = new JMenuItem("About");
menuFile.add(mnuExit);
menuHelp.add(mnuAbout);
menuBar.add(menuFile);
menuBar.add(menuHelp);
setJMenuBar(menuBar);
// ===== FORM =====
JPanel panel = new JPanel(new GridLayout(10, 2));
txtName = new JTextField();
txtPassword = new JPasswordField();
rdoMale = new JRadioButton("Male");
rdoFemale = new JRadioButton("Female");
genderGroup = new ButtonGroup();
genderGroup.add(rdoMale);
genderGroup.add(rdoFemale);
JPanel genderPanel = new JPanel();
genderPanel.add(rdoMale);
genderPanel.add(rdoFemale);
chkSoccer = new JCheckBox("Soccer");
chkReading = new JCheckBox("Reading");
chkSinging = new JCheckBox("Singing");
chkDancing = new JCheckBox("Dancing");
JPanel hobbyPanel = new JPanel();
hobbyPanel.add(chkSoccer);
hobbyPanel.add(chkReading);
hobbyPanel.add(chkSinging);
hobbyPanel.add(chkDancing);
cmbProvince = new JComboBox<>(new String[]{
"Eastern Cape", "Free State", "Gauteng", "KwaZulu-Natal", "Limpopo", "Mpumalanga", "Northern Cape", "North West", "Western Cape"
});
spnAge = new JSpinner(new SpinnerNumberModel(18, 10, 100, 1));
sldSatisfaction = new JSlider(0, 100, 50);
sldSatisfaction.setPaintTicks(true);
sldSatisfaction.setPaintLabels(true);
txtComments = new JTextArea(3, 20);
scrollPane = new JScrollPane(txtComments);
btnChooseFile = new JButton("Choose File");
btnRegister = new JButton("Register");
fileChooser = new JFileChooser();
progressBar = new JProgressBar(0, 100);
progressBar.setStringPainted(true);
panel.add(new JLabel("Name:"));
panel.add(txtName);
panel.add(new JLabel("Password:"));
panel.add(txtPassword);
panel.add(new JLabel("Gender:"));
panel.add(genderPanel);
panel.add(new JLabel("Hobbies:"));
panel.add(hobbyPanel);
panel.add(new JLabel("Province:"));
panel.add(cmbProvince);
panel.add(new JLabel("Age:"));
panel.add(spnAge);
panel.add(new JLabel("Satisfaction:"));
panel.add(sldSatisfaction);
panel.add(new JLabel("Comments:"));
panel.add(scrollPane);
panel.add(btnChooseFile);
panel.add(btnRegister);
add(panel, BorderLayout.CENTER);
add(progressBar, BorderLayout.SOUTH);
// ===== EVENTS =====
btnRegister.addActionListener(e -> {
String name = txtName.getText();
String password = new String(txtPassword.getPassword());
String gender = rdoMale.isSelected() ? "Male" : "Female";
String hobbies = "";
if (chkSoccer.isSelected()) hobbies += "Soccer ";
if (chkReading.isSelected()) hobbies += "Reading ";
if (chkSinging.isSelected()) hobbies += "Singing ";
if (chkDancing.isSelected()) hobbies += "Dancing ";
String province = cmbProvince.getSelectedItem().toString();
int age = (int) spnAge.getValue();
int satisfaction = sldSatisfaction.getValue();
progressBar.setValue(100);
JOptionPane.showMessageDialog(this,
"Name: " + name +
"\nPassword: " + password +
"\nGender: " + gender +
"\nHobbies: " + hobbies +
"\nProvince: " + province +
"\nAge: " + age +
"\nSatisfaction: " + satisfaction +
"\nComments: " + txtComments.getText()
);
});
btnChooseFile.addActionListener(e -> {
int result = fileChooser.showOpenDialog(this);
if (result == JFileChooser.APPROVE_OPTION) {
JOptionPane.showMessageDialog(this,
fileChooser.getSelectedFile().getName());
}
});
mnuExit.addActionListener(e -> System.exit(0));
mnuAbout.addActionListener(e -> JOptionPane.showMessageDialog(this,
"Student Registration System v1.0"));
sldSatisfaction.addChangeListener(e ->
progressBar.setValue(sldSatisfaction.getValue())
);
setVisible(true);
}
}