-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathAccountController.java
More file actions
83 lines (71 loc) · 2.67 KB
/
Copy pathAccountController.java
File metadata and controls
83 lines (71 loc) · 2.67 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
package sample.controller;
import animatefx.animation.FadeIn;
import com.mysql.cj.x.protobuf.MysqlxCrud;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import javax.swing.*;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ResourceBundle;
public class AccountController implements Initializable {
@FXML
private Button btnLogin;
@FXML
private Button btnSignUp;
@FXML
private TextField txtUser;
@FXML
private PasswordField txtPassword;
@FXML
void mouseLogin(MouseEvent event) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3307/users?" + "user=root&password=password");
PreparedStatement ps = con.prepareStatement("SELECT * FROM users WHERE username =? AND password =?");
ps.setString(1, txtUser.getText());
ps.setString(2, txtPassword.getText());
ResultSet rs = ps.executeQuery();
if (rs.next()) {
JOptionPane.showMessageDialog(null, "You are logged in");
} else {
JOptionPane.showMessageDialog(null, "Wrong password or username");
}
} catch (Exception e) {
System.err.println(e.getMessage());
}
if (event.getSource() instanceof Button) {
if (event.getSource() == btnLogin) {
new FadeIn(btnLogin).play();
}
}
}
@Override
public void initialize(URL location, ResourceBundle resources) {
}
public void mouseSignUp(MouseEvent em) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3307/users?" + "user=root&password=password");
PreparedStatement pss = con.prepareStatement("INSERT INTO users SET username =? , password =?");
pss.setString(1, txtUser.getText());
pss.setString(2, txtPassword.getText());
pss.executeUpdate();
} catch (Exception ee) {
JOptionPane.showMessageDialog(null, "Wrong password or username");
} finally {
JOptionPane.showMessageDialog(null, "Success . You have created an account.");
}
if (em.getSource() instanceof Button) {
if (em.getSource() == btnSignUp) {
new FadeIn(btnSignUp).play();
}
}
}
}