Advertisement
Guest User

Untitled

a guest
Jan 9th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.sql.*;
  3. import java.awt.EventQueue;
  4.  
  5. import javax.swing.JFrame;
  6. import javax.swing.JPanel;
  7. import javax.swing.border.EmptyBorder;
  8. import javax.swing.JLabel;
  9. import javax.swing.JOptionPane;
  10. import javax.swing.JTextField;
  11. import javax.swing.JPasswordField;
  12. import javax.swing.JButton;
  13. import java.awt.event.ActionListener;
  14. import java.awt.event.ActionEvent;
  15. import java.sql.*;
  16. public class Login extends JFrame {
  17.  
  18. private JPanel contentPane;
  19. private JTextField Username;
  20. private JPasswordField Password;
  21.  
  22. /**
  23. * Launch the application.
  24. */
  25. public static void main(String[] args) {
  26. EventQueue.invokeLater(new Runnable() {
  27. public void run() {
  28. try {
  29. Login frame = new Login();
  30. frame.setVisible(true);
  31. } catch (Exception e) {
  32. e.printStackTrace();
  33. }
  34. }
  35. });
  36. }
  37.  
  38. /**
  39. * Create the frame.
  40. */
  41. public Login() {
  42. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  43. setBounds(100, 100, 450, 300);
  44. contentPane = new JPanel();
  45. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  46. setContentPane(contentPane);
  47. contentPane.setLayout(null);
  48.  
  49. JLabel lblUsername = new JLabel("Username");
  50. lblUsername.setBounds(41, 30, 80, 40);
  51. contentPane.add(lblUsername);
  52.  
  53. JLabel lblPassword = new JLabel("Password");
  54. lblPassword.setBounds(41, 93, 80, 40);
  55. contentPane.add(lblPassword);
  56.  
  57. Username = new JTextField();
  58. Username.setBounds(169, 30, 189, 40);
  59. contentPane.add(Username);
  60. Username.setColumns(10);
  61.  
  62. Password = new JPasswordField();
  63. Password.setBounds(169, 103, 183, 40);
  64. contentPane.add(Password);
  65.  
  66. JButton btnLogin = new JButton("Login");
  67. btnLogin.addActionListener(new ActionListener() {
  68. public void actionPerformed(ActionEvent arg0) {
  69. try {
  70. Class.forName("com.mysql.cj.jdbc.Driver");
  71. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/quizgame", "root" ,"");
  72. Statement stmt = con.createStatement();
  73. @SuppressWarnings("deprecation")
  74. String sql = "Select * from quizgame where UserName ='"+Username.getText()+"' and Password='"+Password.getText().toString()+"'";
  75. ResultSet rs = stmt.executeQuery(sql);
  76.  
  77. if (rs.next ()) {
  78.  
  79. DifandDom second= new DifandDom(); //Treci la urmatorul JAR
  80. second.setVisible(true);
  81. //JOptionPane.showMessageDialog(null,"Merge frt");
  82. }
  83.  
  84. else
  85. JOptionPane.showMessageDialog(null , "Username sau parola gresite");
  86. con.close();
  87.  
  88. }catch(Exception e ) {System.out.print(e);}
  89. }
  90. });
  91. btnLogin.setBounds(88, 165, 89, 23);
  92. contentPane.add(btnLogin);
  93.  
  94. JButton btnCreateNewAccount = new JButton("Create new account");
  95. btnCreateNewAccount.addActionListener(new ActionListener() {
  96. public void actionPerformed(ActionEvent e) {
  97. Create second= new Create();
  98. second.setVisible(true);
  99. }
  100. });
  101. btnCreateNewAccount.setBounds(88, 214, 153, 23);
  102. contentPane.add(btnCreateNewAccount);
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement