Advertisement
Guest User

Untitled

a guest
Jan 15th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. import java.awt.EventQueue;
  2.  
  3. import java.sql.*;
  4.  
  5. import javax.swing.JFrame;
  6. import javax.swing.JTextField;
  7. import java.awt.Font;
  8. import java.awt.Toolkit;
  9.  
  10. import javax.swing.JPasswordField;
  11. import javax.swing.JButton;
  12. import javax.swing.JTextPane;
  13. import javax.swing.JLabel;
  14. import javax.swing.JOptionPane;
  15.  
  16. import java.awt.event.ActionListener;
  17. import java.awt.event.WindowEvent;
  18. import java.awt.event.ActionEvent;
  19.  
  20. public class Login {
  21.  
  22. private JFrame frame;
  23. private JTextField Username;
  24. private JPasswordField Password;
  25.  
  26. /**
  27. * Launch the application.
  28. */
  29. public static void main(String[] args) {
  30. EventQueue.invokeLater(new Runnable() {
  31. public void run() {
  32. try {
  33. Login window = new Login();
  34. window.frame.setVisible(true);
  35. } catch (Exception e) {
  36. e.printStackTrace();
  37. }
  38. }
  39. });
  40. }
  41.  
  42. /**
  43. * Create the application.
  44. */
  45. public Login() {
  46. initialize();
  47. }
  48.  
  49. /**
  50. * Initialize the contents of the frame.
  51. */
  52. private void initialize() {
  53. frame = new JFrame();
  54. frame.setBounds(100, 100, 403, 384);
  55. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  56. frame.getContentPane().setLayout(null);
  57.  
  58. Username = new JTextField();
  59. Username.setBounds(120, 75, 121, 20);
  60. frame.getContentPane().add(Username);
  61. Username.setColumns(10);
  62.  
  63. Password = new JPasswordField();
  64. Password.setBounds(120, 119, 121, 20);
  65. frame.getContentPane().add(Password);
  66.  
  67. JButton btnLogin = new JButton("Login");
  68. btnLogin.addActionListener(new ActionListener() {
  69. public void actionPerformed(ActionEvent arg0) {
  70. try {
  71. Class.forName("com.mysql.cj.jdbc.Driver");
  72. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/testegrila", "root" ,"");
  73. Statement stmt = con.createStatement();
  74. @SuppressWarnings("deprecation")
  75. String sql = "Select * from mytable where UserName ='"+Username.getText()+"' and Password='"+Password.getText().toString()+"'";
  76. ResultSet rs = stmt.executeQuery(sql);
  77.  
  78. if (rs.next ()) {
  79.  
  80. Game second= new Game();
  81. second.setVisible(true);
  82.  
  83. }
  84.  
  85. else
  86. JOptionPane.showMessageDialog(null , "Username sau parola gresite");
  87. con.close();
  88.  
  89. }catch(Exception e ) {System.out.print(e);}
  90.  
  91.  
  92. }
  93. });
  94. btnLogin.setBounds(120, 220, 121, 31);
  95. frame.getContentPane().add(btnLogin);
  96.  
  97. JLabel lblLoginPage = new JLabel("Login Page");
  98. lblLoginPage.setFont(new Font("Tahoma", Font.PLAIN, 18));
  99. lblLoginPage.setBounds(10, 11, 231, 31);
  100. frame.getContentPane().add(lblLoginPage);
  101.  
  102. JLabel lblUsername = new JLabel("Username");
  103. lblUsername.setBounds(10, 75, 86, 20);
  104. frame.getContentPane().add(lblUsername);
  105.  
  106. JLabel lblPassword = new JLabel("Password");
  107. lblPassword.setBounds(10, 121, 63, 17);
  108. frame.getContentPane().add(lblPassword);
  109.  
  110. JButton btnSignUp = new JButton("Creati Cont");
  111. btnSignUp.addActionListener(new ActionListener() {
  112. public void actionPerformed(ActionEvent arg0) {
  113.  
  114. SignIn second= new SignIn();
  115. second.setVisible(true);
  116.  
  117.  
  118. }
  119. });
  120. btnSignUp.setBounds(288, 300, 89, 23);
  121. frame.getContentPane().add(btnSignUp);
  122. }
  123.  
  124.  
  125.  
  126.  
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement