-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsignup.java
180 lines (153 loc) · 6.31 KB
/
signup.java
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
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
/**
* User Registration using Swing
* @author javaguides.net
*
*/
public class signup extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField firstname;
private JTextField lastname;
private JTextField email;
private JTextField username;
private JTextField mob;
private JPasswordField passwordField;
private JButton btnNewButton;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
signup frame = new signup();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public signup() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(450, 190, 1014, 597);
setResizable(false);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewUserRegister = new JLabel("New User Register");
lblNewUserRegister.setFont(new Font("Times New Roman", Font.PLAIN, 42));
lblNewUserRegister.setBounds(362, 52, 325, 50);
contentPane.add(lblNewUserRegister);
JLabel lblName = new JLabel("First name");
lblName.setFont(new Font("Tahoma", Font.PLAIN, 20));
lblName.setBounds(58, 152, 99, 43);
contentPane.add(lblName);
JLabel lblNewLabel = new JLabel("Last name");
lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 20));
lblNewLabel.setBounds(58, 243, 110, 29);
contentPane.add(lblNewLabel);
JLabel lblEmailAddress = new JLabel("Email\r\n address");
lblEmailAddress.setFont(new Font("Tahoma", Font.PLAIN, 20));
lblEmailAddress.setBounds(58, 324, 124, 36);
contentPane.add(lblEmailAddress);
firstname = new JTextField();
firstname.setFont(new Font("Tahoma", Font.PLAIN, 32));
firstname.setBounds(214, 151, 228, 50);
contentPane.add(firstname);
firstname.setColumns(10);
lastname = new JTextField();
lastname.setFont(new Font("Tahoma", Font.PLAIN, 32));
lastname.setBounds(214, 235, 228, 50);
contentPane.add(lastname);
lastname.setColumns(10);
email = new JTextField();
email.setFont(new Font("Tahoma", Font.PLAIN, 32));
email.setBounds(214, 320, 228, 50);
contentPane.add(email);
email.setColumns(10);
username = new JTextField();
username.setFont(new Font("Tahoma", Font.PLAIN, 32));
username.setBounds(707, 151, 228, 50);
contentPane.add(username);
username.setColumns(10);
JLabel lblUsername = new JLabel("Username");
lblUsername.setFont(new Font("Tahoma", Font.PLAIN, 20));
lblUsername.setBounds(542, 159, 99, 29);
contentPane.add(lblUsername);
JLabel lblPassword = new JLabel("Password");
lblPassword.setFont(new Font("Tahoma", Font.PLAIN, 20));
lblPassword.setBounds(542, 245, 99, 24);
contentPane.add(lblPassword);
JLabel lblMobileNumber = new JLabel("Mobile number");
lblMobileNumber.setFont(new Font("Tahoma", Font.PLAIN, 20));
lblMobileNumber.setBounds(542, 329, 139, 26);
contentPane.add(lblMobileNumber);
mob = new JTextField();
mob.setFont(new Font("Tahoma", Font.PLAIN, 32));
mob.setBounds(707, 320, 228, 50);
contentPane.add(mob);
mob.setColumns(10);
passwordField = new JPasswordField();
passwordField.setFont(new Font("Tahoma", Font.PLAIN, 32));
passwordField.setBounds(707, 235, 228, 50);
contentPane.add(passwordField);
btnNewButton = new JButton("Register");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String firstName = firstname.getText();
String lastName = lastname.getText();
String emailId = email.getText();
String userName = username.getText();
String mobileNumber = mob.getText();
int len = mobileNumber.length();
String password = passwordField.getText();
String msg = "" + firstName;
msg += " \n";
if (len != 10) {
JOptionPane.showMessageDialog(btnNewButton, "Enter a valid mobile number");
}
try {
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/Airlines", "root", "@Aastha1126");
String query = "INSERT INTO account values('" + firstName + "','" + lastName + "','" + userName + "','" +
password + "','" + emailId + "','" + mobileNumber + "')";
Statement sta = connection.createStatement();
int x = sta.executeUpdate(query);
if (x == 0) {
JOptionPane.showMessageDialog(btnNewButton, "This is alredy exist");
} else {
JOptionPane.showMessageDialog(btnNewButton,
"Welcome, " + msg + "Your account is sucessfully created");
}
connection.close();
} catch (Exception exception) {
exception.printStackTrace();
}
}
});
btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 22));
btnNewButton.setBounds(399, 447, 259, 74);
contentPane.add(btnNewButton);
}
}