Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package raizel;
- import java.lang.reflect.Array;
- import java.sql.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class LogInEvents implements ActionListener
- {
- private LogIn li;
- private ConnectToDB ctb;
- public LogInEvents(LogIn lahi)
- {
- this.ctb = new ConnectToDB();
- this.li = lahi;
- }
- @Override
- public void actionPerformed(ActionEvent event)
- {
- //Start Of LogIn Panel
- String username = this.li.getButtonLogIn().getText();
- String password = this.li.getFieldPassword().getText();
- String passwordFromDB="";
- String url = "jdbc:mysql://localhost/practice";
- String userid = "root";
- String pass = "root";
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- }
- catch(java.lang.ClassNotFoundException e)
- {
- System.err.print("ClassNotFound");
- System.err.println(e.getMessage());
- }
- try
- {
- Connection con = DriverManager.getConnection(url,userid,pass);
- Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
- ResultSet rs = stmt.executeQuery("Select * from account where password='"+password+"'");
- rs.next();
- passwordFromDB = rs.getString("password");
- }
- catch(SQLException ex)
- {
- System.out.println("SQLException: " + ex.getMessage());
- }
- if(event.getSource().equals(this.li.getButtonLogIn()))
- {
- if(password.equals(passwordFromDB))
- {
- this.li.showLogPanel(false);
- this.li.MyPanel(true);
- }
- else
- {
- JOptionPane.showMessageDialog(null, "Failed to connect to server","Error",JOptionPane.ERROR_MESSAGE);
- }
- }
- //End Of Log In Panel
- //Inside MyPanel after Log In Panel
- if(event.getSource().equals(this.li.getButtonLogOut()))
- {
- this.li.showLogPanel(true);
- this.li.MyPanel(false);
- }
- else if(event.getSource().equals(this.li.getButtonDelete()))
- {
- this.li.MyPanel(false);
- this.li.showDelPanel(true);
- this.li.showLogPanel(false);
- }
- //Start of SignUp Panel
- else if(event.getSource().equals(this.li.getButtonSignUp()))
- {
- this.li.showLogPanel(false);
- this.li.SignUpPanel(true);
- }
- String name = this.li.getFieldSignName().getText();
- String Username = this.li.getFieldSignUserName().getText();
- String Password = this.li.getFieldSignPassword().getText();
- if(event.getSource().equals(this.li.getButtonRegister()))
- {
- this.ctb.add(name, Username, Password);
- JOptionPane.showMessageDialog(null, "Registration Successful! ");
- }
- //End of Sign Up Panel
- //Return To LogIn Panel
- else if(event.getSource().equals(this.li.getButtonBack()))
- {
- this.li.showLogPanel(true);
- this.li.SignUpPanel(false);
- }
- }
- }
Add Comment
Please, Sign In to add comment