-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegistration Form (GUI based).java
More file actions
82 lines (64 loc) · 2.57 KB
/
Registration Form (GUI based).java
File metadata and controls
82 lines (64 loc) · 2.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
//Registration form with Name, Email and Password as fields
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class RegistrationForm extends Frame {
private TextField nameTextField;
private TextField emailTextField;
private TextField passwordTextField;
public RegistrationForm() {
setTitle("Registration Form");
setSize(300, 280);
setLayout(new FlowLayout());
Label nameLabel = new Label("Name*:");
Label emailLabel = new Label("Email*:");
Label passwordLabel = new Label("Password*:");
nameTextField = new TextField(30);
emailTextField = new TextField(30);
passwordTextField = new TextField(30);
passwordTextField.setEchoChar('*');
Button submitButton = new Button("Submit");
Button cancelButton = new Button("Cancel");
add(nameLabel);
add(nameTextField);
add(emailLabel);
add(emailTextField);
add(passwordLabel);
add(passwordTextField);
add(submitButton);
add(cancelButton);
submitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = nameTextField.getText();
String email = emailTextField.getText();
String password = passwordTextField.getText();
// checks if all the fields are filled
if (name.isEmpty() || email.isEmpty() || password.isEmpty()) {
showMessage("Please fill in all required fields.");
} else {
showMessage("Registration successful:\nName: " + name + "\nEmail: " + email);
}
}
});
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
nameTextField.setText("");
emailTextField.setText("");
passwordTextField.setText("");
showMessage("Registration canceled.");
}
});
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
}
private void showMessage(String message) {
JOptionPane.showMessageDialog(this, message, "Message", JOptionPane.INFORMATION_MESSAGE);
}
public static void main(String[] args) {
RegistrationForm registrationForm = new RegistrationForm();
registrationForm.setVisible(true);
}
}