-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignupOne.java
More file actions
212 lines (168 loc) · 7.08 KB
/
Copy pathSignupOne.java
File metadata and controls
212 lines (168 loc) · 7.08 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import com.toedter.calendar.JDateChooser;
import java.sql.*;
import java.text.SimpleDateFormat;
public class SignupOne extends JFrame implements ActionListener {
JTextField nameField, fnameField, emailField, addressField, cityField, stateField, pinField;
JDateChooser dateChooser;
JRadioButton male, female, married, unmarried, other;
JButton next;
String formNo;
SignupOne() {
setLayout(null);
setTitle("NEW ACCOUNT APPLICATION - PAGE 1");
// Generate a random 4-digit form number
formNo = "" + Math.abs((int)(Math.random() * 9000 + 1000));
JLabel formLabel = new JLabel("APPLICATION FORM NO. " + formNo);
formLabel.setFont(new Font("Raleway", Font.BOLD, 30));
formLabel.setBounds(180, 20, 600, 40);
add(formLabel);
JLabel personalDetails = new JLabel("Page 1: Personal Details");
personalDetails.setFont(new Font("Raleway", Font.BOLD, 22));
personalDetails.setBounds(290, 70, 400, 30);
add(personalDetails);
// Fields...
JLabel name = new JLabel("Name:");
name.setFont(new Font("Raleway", Font.PLAIN, 18));
name.setBounds(100, 120, 100, 30);
add(name);
nameField = new JTextField();
nameField.setBounds(300, 120, 400, 30);
add(nameField);
JLabel fname = new JLabel("Father's Name:");
fname.setFont(new Font("Raleway", Font.PLAIN, 18));
fname.setBounds(100, 170, 150, 30);
add(fname);
fnameField = new JTextField();
fnameField.setBounds(300, 170, 400, 30);
add(fnameField);
JLabel dob = new JLabel("Date of Birth:");
dob.setFont(new Font("Raleway", Font.PLAIN, 18));
dob.setBounds(100, 220, 150, 30);
add(dob);
dateChooser = new JDateChooser();
dateChooser.setBounds(300, 220, 400, 30);
add(dateChooser);
JLabel gender = new JLabel("Gender:");
gender.setFont(new Font("Raleway", Font.PLAIN, 18));
gender.setBounds(100, 270, 100, 30);
add(gender);
male = new JRadioButton("Male");
male.setBounds(300, 270, 100, 30);
male.setBackground(Color.WHITE);
add(male);
female = new JRadioButton("Female");
female.setBounds(450, 270, 100, 30);
female.setBackground(Color.WHITE);
add(female);
ButtonGroup genderGroup = new ButtonGroup();
genderGroup.add(male);
genderGroup.add(female);
JLabel email = new JLabel("Email Address:");
email.setFont(new Font("Raleway", Font.PLAIN, 18));
email.setBounds(100, 320, 150, 30);
add(email);
emailField = new JTextField();
emailField.setBounds(300, 320, 400, 30);
add(emailField);
JLabel marital = new JLabel("Marital Status:");
marital.setFont(new Font("Raleway", Font.PLAIN, 18));
marital.setBounds(100, 370, 150, 30);
add(marital);
married = new JRadioButton("Married");
married.setBounds(300, 370, 100, 30);
married.setBackground(Color.WHITE);
add(married);
unmarried = new JRadioButton("Unmarried");
unmarried.setBounds(400, 370, 100, 30);
unmarried.setBackground(Color.WHITE);
add(unmarried);
other = new JRadioButton("Other");
other.setBounds(500, 370, 100, 30);
other.setBackground(Color.WHITE);
add(other);
ButtonGroup maritalGroup = new ButtonGroup();
maritalGroup.add(married);
maritalGroup.add(unmarried);
maritalGroup.add(other);
JLabel address = new JLabel("Address:");
address.setFont(new Font("Raleway", Font.PLAIN, 18));
address.setBounds(100, 420, 150, 30);
add(address);
addressField = new JTextField();
addressField.setBounds(300, 420, 400, 30);
add(addressField);
JLabel city = new JLabel("City:");
city.setFont(new Font("Raleway", Font.PLAIN, 18));
city.setBounds(100, 470, 150, 30);
add(city);
cityField = new JTextField();
cityField.setBounds(300, 470, 400, 30);
add(cityField);
JLabel state = new JLabel("State:");
state.setFont(new Font("Raleway", Font.PLAIN, 18));
state.setBounds(100, 520, 150, 30);
add(state);
stateField = new JTextField();
stateField.setBounds(300, 520, 400, 30);
add(stateField);
JLabel pin = new JLabel("Pin Code:");
pin.setFont(new Font("Raleway", Font.PLAIN, 18));
pin.setBounds(100, 570, 150, 30);
add(pin);
pinField = new JTextField();
pinField.setBounds(300, 570, 400, 30);
add(pinField);
next = new JButton("Next");
next.setBounds(620, 630, 80, 30);
next.addActionListener(this);
add(next);
getContentPane().setBackground(Color.WHITE);
setSize(850, 720);
setLocation(350, 10);
setVisible(true);
}
public static void main(String[] args) {
new SignupOne();
}
@Override
public void actionPerformed(ActionEvent e) {
try {
String name = nameField.getText();
String fname = fnameField.getText();
java.util.Date selectedDate = dateChooser.getDate();
String dob = "";
if (selectedDate != null) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
dob = sdf.format(selectedDate);
} else {
JOptionPane.showMessageDialog(null, "Please select Date of Birth");
return; // Exit early to avoid error
}
String gender = male.isSelected() ? "Male" : female.isSelected() ? "Female" : "";
String email = emailField.getText();
String marital = married.isSelected() ? "Married" : unmarried.isSelected() ? "Unmarried" : other.isSelected() ? "Other" : "";
String address = addressField.getText();
String city = cityField.getText();
String state = stateField.getText();
String pin = pinField.getText();
if (name.equals("") || fname.equals("") || dob.equals("") || gender.equals("") || email.equals("") || marital.equals("") || address.equals("") || city.equals("") || state.equals("") || pin.equals("")) {
JOptionPane.showMessageDialog(null, "Please fill all fields");
} else {
Conn c = new Conn();
String query = "INSERT INTO signup (formno, name, fname, dob, gender, email, marital, address, city, state, pincode) " +
"VALUES('" + formNo + "','" + name + "','" + fname + "','" + dob + "','" + gender + "','" + email + "','" + marital + "','" + address + "','" + city + "','" + state + "','" + pin + "')";
c.s.executeUpdate(query);
c.s.executeUpdate(query);
JOptionPane.showMessageDialog(null, "Form Submitted");
// Proceed to SignupTwo and pass form number
setVisible(false);
new SignupTwo(formNo);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}