Guest User

Untitled

a guest
Nov 27th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. package raizel;
  2.  
  3. import java.lang.reflect.Array;
  4. import java.sql.*;
  5. import java.awt.event.*;
  6. import javax.swing.*;
  7.  
  8.  
  9.  
  10. public class LogInEvents implements ActionListener
  11. {
  12. private LogIn li;
  13. private ConnectToDB ctb;
  14. public LogInEvents(LogIn lahi)
  15. {
  16. this.ctb = new ConnectToDB();
  17. this.li = lahi;
  18.  
  19. }
  20.  
  21. @Override
  22. public void actionPerformed(ActionEvent event)
  23. {
  24.  
  25. //Start Of LogIn Panel
  26. String username = this.li.getButtonLogIn().getText();
  27. String password = this.li.getFieldPassword().getText();
  28. String passwordFromDB="";
  29. String url = "jdbc:mysql://localhost/practice";
  30. String userid = "root";
  31. String pass = "root";
  32. try
  33. {
  34. Class.forName("com.mysql.jdbc.Driver");
  35. }
  36. catch(java.lang.ClassNotFoundException e)
  37. {
  38. System.err.print("ClassNotFound");
  39. System.err.println(e.getMessage());
  40.  
  41. }
  42. try
  43. {
  44. Connection con = DriverManager.getConnection(url,userid,pass);
  45. Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
  46. ResultSet rs = stmt.executeQuery("Select * from account where password='"+password+"'");
  47. rs.next();
  48. passwordFromDB = rs.getString("password");
  49. }
  50. catch(SQLException ex)
  51. {
  52. System.out.println("SQLException: " + ex.getMessage());
  53. }
  54.  
  55.  
  56.  
  57. if(event.getSource().equals(this.li.getButtonLogIn()))
  58. {
  59.  
  60. if(password.equals(passwordFromDB))
  61. {
  62. this.li.showLogPanel(false);
  63. this.li.MyPanel(true);
  64.  
  65. }
  66. else
  67. {
  68. JOptionPane.showMessageDialog(null, "Failed to connect to server","Error",JOptionPane.ERROR_MESSAGE);
  69. }
  70.  
  71. }
  72.  
  73. //End Of Log In Panel
  74.  
  75.  
  76.  
  77. //Inside MyPanel after Log In Panel
  78.  
  79. if(event.getSource().equals(this.li.getButtonLogOut()))
  80. {
  81. this.li.showLogPanel(true);
  82. this.li.MyPanel(false);
  83. }
  84.  
  85. else if(event.getSource().equals(this.li.getButtonDelete()))
  86. {
  87. this.li.MyPanel(false);
  88. this.li.showDelPanel(true);
  89. this.li.showLogPanel(false);
  90. }
  91.  
  92. //Start of SignUp Panel
  93. else if(event.getSource().equals(this.li.getButtonSignUp()))
  94. {
  95. this.li.showLogPanel(false);
  96. this.li.SignUpPanel(true);
  97. }
  98. String name = this.li.getFieldSignName().getText();
  99. String Username = this.li.getFieldSignUserName().getText();
  100. String Password = this.li.getFieldSignPassword().getText();
  101. if(event.getSource().equals(this.li.getButtonRegister()))
  102. {
  103. this.ctb.add(name, Username, Password);
  104. JOptionPane.showMessageDialog(null, "Registration Successful! ");
  105. }
  106. //End of Sign Up Panel
  107.  
  108. //Return To LogIn Panel
  109. else if(event.getSource().equals(this.li.getButtonBack()))
  110. {
  111. this.li.showLogPanel(true);
  112. this.li.SignUpPanel(false);
  113. }
  114.  
  115. }
  116.  
  117. }
Add Comment
Please, Sign In to add comment