-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegistrationSystem.java
More file actions
124 lines (112 loc) · 5.26 KB
/
Copy pathRegistrationSystem.java
File metadata and controls
124 lines (112 loc) · 5.26 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
import javax.swing.*;
import java.io.File;
public class RegistrationSystem {
public static void main(String[] args) {
JFrame frame = new JFrame("Registration Form");
frame.setSize(400, 400);
frame.setLayout(null);
JLabel usernameLabel = new JLabel("Username:");
usernameLabel.setBounds(10,10,100,20);
frame.add(usernameLabel);
JTextField usernameField = new JTextField();
usernameField.setBounds(100,10,100,20);
frame.add(usernameField);
JLabel emailLabel = new JLabel("Email:");
emailLabel.setBounds(10,40,100,20);
frame.add(emailLabel);
JTextField emailField = new JTextField();
emailField.setBounds(100,40,100,20);
frame.add(emailField);
JLabel passwordLabel = new JLabel("Password:");
passwordLabel.setBounds(10,70,100,20);
frame.add(passwordLabel);
JPasswordField passwordField = new JPasswordField();
passwordField.setBounds(100,70,100,20);
frame.add(passwordField);
JLabel genderLabel = new JLabel("Gender:");
genderLabel.setBounds(10,100,100,20);
frame.add(genderLabel);
JRadioButton male = new JRadioButton("Male");
male.setBounds(100,100,70,20);
frame.add(male);
JRadioButton female = new JRadioButton("Female");
female.setBounds(170,100,70,20);
frame.add(female);
ButtonGroup genderGroup = new ButtonGroup();
genderGroup.add(male);
genderGroup.add(female);
JLabel countryLabel = new JLabel("Country:");
countryLabel.setBounds(10,130,100,20);
frame.add(countryLabel);
String[] countries = {"Select","Bangladesh","India","Pakistan","Afghanistan","Saudi Arabia","Palestine","Iran"};
JComboBox<String> countryComboBox = new JComboBox<>(countries);
countryComboBox.setBounds(100,130,100,20);
frame.add(countryComboBox);
JLabel DOBLabel = new JLabel("Date of Birth:");
DOBLabel.setBounds(10,160,100,20);
frame.add(DOBLabel);
String[] days = new String[31];
for (int i = 1; i <= 31; i++) {
days[i-1] = String.valueOf(i);
}
String[] months = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
String[] years = new String[100];
for (int i = 0; i < 100; i++) {
years[i] = String.valueOf(2025-i);
}
JComboBox<String> dayComboBox = new JComboBox<>(days);
dayComboBox.setBounds(100,160,50,20);
JComboBox<String > monthComboBox = new JComboBox<>(months);
monthComboBox.setBounds(150,160,50,20);
JComboBox<String> yearComboBox = new JComboBox<>(years);
yearComboBox.setBounds(200,160,60,20);
frame.add(dayComboBox);
frame.add(monthComboBox);
frame.add(yearComboBox);
JLabel fileLabel = new JLabel("Profile Picture:");
fileLabel.setBounds(10,190,100,20);
frame.add(fileLabel);
JButton uploadButton = new JButton("Choose file");
uploadButton.setBounds(100,190,100,20);
frame.add(uploadButton);
JLabel filePathLabel = new JLabel("");
filePathLabel.setBounds(100,220,300,20);
frame.add(filePathLabel);
final String[] selectedFilePath = {""};
uploadButton.addActionListener(e -> {
JFileChooser fileChooser = new JFileChooser();
int returnValue = fileChooser.showOpenDialog(frame);
if(returnValue == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
selectedFilePath[0] = file.getAbsolutePath();
filePathLabel.setText(file.getName());
}
});
JButton submitButton = new JButton("Submit");
submitButton.setBounds(100,250,80,20);
frame.add(submitButton);
submitButton.addActionListener(e -> {
String username = usernameField.getText();
String email = emailField.getText();
String password = String.valueOf(passwordField.getPassword());
String gender = male.isSelected() ? "Male" : female.isSelected() ? "Female" : "Not Selected";
String country = (String) countryComboBox.getSelectedItem();
String dateOfBirth = dayComboBox.getSelectedItem()+" "+monthComboBox.getSelectedItem()+","+yearComboBox.getSelectedItem();
if(username.isEmpty() || email.isEmpty() || password.isEmpty() || gender.equals("Not Selected") || country.equals("Select") ) {
JOptionPane.showMessageDialog(frame, "Please fill all the fields","Error",JOptionPane.ERROR_MESSAGE);
} else {
JOptionPane.showMessageDialog(frame, "Registration Successful\n"
+ "\nUsername: " + username
+ "\nEmail: " + email
+ "\nPassword: " + password
+ "\nGender: " + gender
+ "\nCountry: " + country
+ "\nDate of Birth: " + dateOfBirth
+ "\nPhoto: " + (selectedFilePath[0].isEmpty() ? "Not uploaded" : filePathLabel.getText())
,"Success", JOptionPane.INFORMATION_MESSAGE);
}
});
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}