Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.EventQueue;
- import java.sql.*;
- import javax.swing.JFrame;
- import javax.swing.JTextField;
- import java.awt.Font;
- import java.awt.Toolkit;
- import javax.swing.JPasswordField;
- import javax.swing.JButton;
- import javax.swing.JTextPane;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import java.awt.event.ActionListener;
- import java.awt.event.WindowEvent;
- import java.awt.event.ActionEvent;
- public class Login {
- private JFrame frame;
- private JTextField Username;
- private JPasswordField Password;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Login window = new Login();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public Login() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frame = new JFrame();
- frame.setBounds(100, 100, 403, 384);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(null);
- Username = new JTextField();
- Username.setBounds(120, 75, 121, 20);
- frame.getContentPane().add(Username);
- Username.setColumns(10);
- Password = new JPasswordField();
- Password.setBounds(120, 119, 121, 20);
- frame.getContentPane().add(Password);
- JButton btnLogin = new JButton("Login");
- btnLogin.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- try {
- Class.forName("com.mysql.cj.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/testegrila", "root" ,"");
- Statement stmt = con.createStatement();
- @SuppressWarnings("deprecation")
- String sql = "Select * from mytable where UserName ='"+Username.getText()+"' and Password='"+Password.getText().toString()+"'";
- ResultSet rs = stmt.executeQuery(sql);
- if (rs.next ()) {
- Game second= new Game();
- second.setVisible(true);
- }
- else
- JOptionPane.showMessageDialog(null , "Username sau parola gresite");
- con.close();
- }catch(Exception e ) {System.out.print(e);}
- }
- });
- btnLogin.setBounds(120, 220, 121, 31);
- frame.getContentPane().add(btnLogin);
- JLabel lblLoginPage = new JLabel("Login Page");
- lblLoginPage.setFont(new Font("Tahoma", Font.PLAIN, 18));
- lblLoginPage.setBounds(10, 11, 231, 31);
- frame.getContentPane().add(lblLoginPage);
- JLabel lblUsername = new JLabel("Username");
- lblUsername.setBounds(10, 75, 86, 20);
- frame.getContentPane().add(lblUsername);
- JLabel lblPassword = new JLabel("Password");
- lblPassword.setBounds(10, 121, 63, 17);
- frame.getContentPane().add(lblPassword);
- JButton btnSignUp = new JButton("Creati Cont");
- btnSignUp.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- SignIn second= new SignIn();
- second.setVisible(true);
- }
- });
- btnSignUp.setBounds(288, 300, 89, 23);
- frame.getContentPane().add(btnSignUp);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement