-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignup.java
More file actions
141 lines (122 loc) · 4.89 KB
/
Signup.java
File metadata and controls
141 lines (122 loc) · 4.89 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
package ngomanagement3;
import java.awt.Color;
import java.awt.Font;
import java.sql.*;
import java.sql.ResultSet;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Signup extends JFrame implements ActionListener {
JTextField nameField, emailField, phoneField;
JPasswordField passwordField;
JButton signupBtn, backBtn;
public Signup() {
setTitle("Volunteer Sign Up");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(420, 400);
setLocation(400, 270);
setResizable(false);
JPanel panel = new JPanel();
panel.setBackground(Color.BLACK);
panel.setLayout(null);
JLabel title = new JLabel("VOLUNTEER SIGN UP", JLabel.CENTER);
title.setFont(new Font("Segoe UI", Font.BOLD, 22));
title.setForeground(new Color(102, 255, 178));
title.setBounds(0, 10, 420, 40);
panel.add(title);
JLabel nameLabel = new JLabel("Name:");
nameLabel.setBounds(50, 60, 100, 30);
nameLabel.setFont(new Font("Tahoma", Font.BOLD, 16));
nameLabel.setForeground(new Color(102, 255, 178));
panel.add(nameLabel);
nameField = new JTextField();
nameField.setBounds(160, 60, 180, 30);
nameField.setBackground(new Color(25, 25, 25));
nameField.setForeground(new Color(102, 255, 178));
nameField.setCaretColor(new Color(102, 255, 178));
nameField.setBorder(BorderFactory.createLineBorder(new Color(102, 255, 178), 1));
panel.add(nameField);
JLabel emailLabel = new JLabel("Email:");
emailLabel.setBounds(50, 105, 100, 30);
emailLabel.setFont(new Font("Tahoma", Font.BOLD, 16));
emailLabel.setForeground(new Color(102, 255, 178));
panel.add(emailLabel);
emailField = new JTextField();
emailField.setBounds(160, 105, 180, 30);
emailField.setBackground(new Color(25, 25, 25));
emailField.setForeground(new Color(102, 255, 178));
emailField.setBorder(BorderFactory.createLineBorder(new Color(102, 255, 178), 1));
panel.add(emailField);
JLabel phoneLabel = new JLabel("Phone:");
phoneLabel.setBounds(50, 150, 100, 30);
phoneLabel.setFont(new Font("Tahoma", Font.BOLD, 16));
phoneLabel.setForeground(new Color(102, 255, 178));
panel.add(phoneLabel);
phoneField = new JTextField();
phoneField.setBounds(160, 150, 180, 30);
phoneField.setBackground(new Color(25, 25, 25));
phoneField.setForeground(new Color(102, 255, 178));
phoneField.setBorder(BorderFactory.createLineBorder(new Color(102, 255, 178), 1));
panel.add(phoneField);
JLabel passwordLabel = new JLabel("Password:");
passwordLabel.setBounds(50, 195, 100, 30);
passwordLabel.setFont(new Font("Tahoma", Font.BOLD, 16));
passwordLabel.setForeground(new Color(102, 255, 178));
panel.add(passwordLabel);
passwordField = new JPasswordField();
passwordField.setBounds(160, 195, 180, 30);
passwordField.setBackground(new Color(25, 25, 25));
passwordField.setForeground(new Color(102, 255, 178));
passwordField.setBorder(BorderFactory.createLineBorder(new Color(102, 255, 178), 1));
panel.add(passwordField);
signupBtn = new JButton("Sign Up");
signupBtn.setBounds(70, 260, 120, 35);
signupBtn.setFont(new Font("Segoe UI", Font.BOLD, 16));
signupBtn.setBackground(new Color(102, 255, 178));
signupBtn.setForeground(Color.BLACK);
signupBtn.addActionListener(this);
panel.add(signupBtn);
backBtn = new JButton("Back");
backBtn.setBounds(220, 260, 120, 35);
backBtn.setFont(new Font("Segoe UI", Font.BOLD, 16));
backBtn.setBackground(Color.BLACK);
backBtn.setForeground(new Color(102, 255, 178));
backBtn.addActionListener(e -> {
setVisible(false);
new Login();
});
panel.add(backBtn);
add(panel);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
String name = nameField.getText();
String email = emailField.getText();
String phone = phoneField.getText();
String password = new String(passwordField.getPassword());
if (name.isEmpty() || email.isEmpty() || phone.isEmpty() || password.isEmpty()) {
JOptionPane.showMessageDialog(this, "All fields are required!", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ngo_management", "root",
"root")) {
String q = "INSERT INTO volunteer (volunteer_name, email, phone_number, password) VALUES (?, ?, ?, ?)";
PreparedStatement pstmt = conn.prepareStatement(q);
pstmt.setString(1, name);
pstmt.setString(2, email);
pstmt.setString(3, phone);
pstmt.setString(4, password);
pstmt.executeUpdate();
JOptionPane.showMessageDialog(this, "Sign Up successful! You can now login.");
setVisible(false);
new Login();
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(this, "Sign Up failed!", "Error", JOptionPane.ERROR_MESSAGE);
}
}
public static void main(String[] args) {
new Signup();
}
}