-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegistrationForm.java
More file actions
56 lines (48 loc) · 2.38 KB
/
Copy pathRegistrationForm.java
File metadata and controls
56 lines (48 loc) · 2.38 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
import javax.swing.*;
class RegistrationForm {
public static void main(String[] args) {
JFrame frame = new JFrame("Registration Form");
JLabel nameLabel = new JLabel("Name:");
JLabel emailLabel = new JLabel("Email:");
JLabel passLabel = new JLabel("Password:");
JLabel confirmPassLabel = new JLabel("Confirm Password:");
JTextField nameField = new JTextField();
JTextField emailField = new JTextField();
JPasswordField passField = new JPasswordField();
JPasswordField confirmPassField = new JPasswordField();
JButton registerButton = new JButton("Register");
nameLabel.setBounds(50, 30, 150, 25);
emailLabel.setBounds(50, 70, 150, 25);
passLabel.setBounds(50, 110, 150, 25);
confirmPassLabel.setBounds(50, 150, 150, 25);
nameField.setBounds(200, 30, 200, 25);
emailField.setBounds(200, 70, 200, 25);
passField.setBounds(200, 110, 200, 25);
confirmPassField.setBounds(200, 150, 200, 25);
registerButton.setBounds(200, 190, 100, 30);
frame.add(nameLabel); frame.add(nameField);
frame.add(emailLabel); frame.add(emailField);
frame.add(passLabel); frame.add(passField);
frame.add(confirmPassLabel); frame.add(confirmPassField);
frame.add(registerButton);
registerButton.addActionListener(e -> {
String name = nameField.getText();
String email = emailField.getText();
String pass = new String(passField.getPassword());
String confirmPass = new String(confirmPassField.getPassword());
if (name.isEmpty() || email.isEmpty() || pass.isEmpty() || confirmPass.isEmpty()) {
JOptionPane.showMessageDialog(frame, "All fields are required.");
} else if (!email.contains("@")) {
JOptionPane.showMessageDialog(frame, "Invalid email address.");
} else if (!pass.equals(confirmPass)) {
JOptionPane.showMessageDialog(frame, "Passwords do not match.");
} else {
JOptionPane.showMessageDialog(frame, "Registration successful!");
}
});
frame.setSize(500, 300);
frame.setLayout(null);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}