-
Notifications
You must be signed in to change notification settings - Fork 0
/
Onee.java
120 lines (114 loc) · 3.37 KB
/
Onee.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
package second;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class Onee extends JFrame implements ActionListener{
JButton btn_submit;
JLabel labe;
JButton login;
JButton alogin;
JButton btn_exit;
JTextField tf_username;
JTextField tf_password;
JLabel l_registration;
JLabel l_username;
JLabel l_password;
JLabel mail;
JTextField email;
public Onee(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mail = new JLabel("E-mail");
email = new JTextField();
email.setBounds(300,140,80,30);
mail.setBounds(120,140,80,30);
setTitle("Registration");
alogin = new JButton("Admin login");
alogin.setBounds(330,250,150,30);
alogin.setForeground(Color.white);
alogin.setBackground(Color.black);
login = new JButton("User Login");
login.setBounds(330,200,150,30);
login.setForeground(Color.white);
login.setBackground(Color.black);
labe = new JLabel("Note: Use numbers and special characters for a strong password");
l_registration = new JLabel("REGISTRATION FROM");
l_registration.setForeground(Color.red);
labe.setBounds(50,280,400,40);
labe.setForeground(Color.red);
l_registration.setBounds(230,0,250,40);
l_username = new JLabel("USERNAME");
l_username.setBounds(120,40,80,30);
tf_username = new JTextField();
tf_username.setBounds(300,40,80,30);
l_password = new JLabel("CREATE PASSWORD");
l_password.setBounds(100,90,200,30);
tf_password = new JTextField();
tf_password.setBounds(300,90,80,30);
btn_submit = new JButton("SUBMIT");
btn_submit.setBounds(100,200,100,30);
btn_submit.setForeground(Color.white);
btn_submit.setBackground(Color.black);
btn_submit.addActionListener(this);
btn_exit = new JButton("EXIT");
btn_exit.setBounds(225,200,80,30);
btn_exit.setForeground(Color.white);
btn_exit.setBackground(Color.black);
btn_exit.addActionListener(this);
login.addActionListener(this);
add(btn_submit);
add(btn_exit);
add(tf_username);
add(tf_password);
add(l_username);
add(l_password);
add(labe);
add(l_registration);
add(login);
//add(alogin);
add(email);
add(mail);
setLayout(null);
setSize(600,400);
setLocationRelativeTo(null);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e){
String name= tf_username.getText().toString();
if(e.getSource() == login) {
this.dispose();
new sec();
}
if (e.getSource() == btn_submit) {
String use = tf_username.getText().toString();
String pas = tf_password.getText().toString();
try{
Class.forName("com.mysql.cj.jdbc.Driver"); // step1
String mysqlUrl = "jdbc:mysql://localhost:3306/authentication";
// step2
Connection con = DriverManager.getConnection(mysqlUrl, "root", "vishnu");
// System.out.println("Connection established......");
// step3
PreparedStatement ps = con.prepareStatement("insert into usercreds values(?,?)");
ps.setString(1, use);
ps.setString(2, pas);
// step4
ps.execute();
// step5
con.close();
} catch (Exception ea) {
ea.printStackTrace();
}
tf_username.setText("");
tf_password.setText("");
this.dispose();
new sec();
}
if(e.getSource() == btn_exit) {
dispose();
}
}
}