Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package login;
  2.  
  3. import java.awt.Cursor;
  4.  
  5. public class Frame_Login {
  6.  
  7.     public JFrame frame_login;
  8.     private JTextField text_user;
  9.     private JPasswordField text_pass;
  10.     private JButton btnLogIn,btnExit;
  11.    
  12.     private String us,ps,SQL_LogIn;
  13.    
  14.     public static void main(String[] args) {
  15.        
  16.         try {
  17.             UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
  18.         } catch (ClassNotFoundException | InstantiationException
  19.                 | IllegalAccessException | UnsupportedLookAndFeelException e1) {
  20.             System.exit(0);
  21.         }
  22.         EventQueue.invokeLater(new Runnable() {
  23.             public void run() {
  24.                 try {
  25.                     Frame_Login window = new Frame_Login();
  26.                     window.frame_login.setVisible(true);
  27.                 } catch (Exception e) {
  28.                     e.printStackTrace();
  29.                 }
  30.             }
  31.         });
  32.     }
  33.  
  34.     public Frame_Login() {
  35.         initialize();
  36.     }
  37.  
  38.  
  39.     private void initialize() {
  40.         frame_login = new JFrame();
  41.         frame_login.getContentPane().setFont(new Font("Verdana", Font.PLAIN, 12));
  42.         frame_login.setBounds(100, 100, 394, 246);
  43.         frame_login.setTitle("Frame Log In");
  44.         frame_login.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  45.         frame_login.setResizable(false);
  46.         frame_login.getContentPane().setLayout(null);
  47.        
  48.         JLabel lblUsername = new JLabel("USERNAME");
  49.         lblUsername.setFont(new Font("Verdana", Font.PLAIN, 12));
  50.         lblUsername.setBounds(33, 56, 102, 25);
  51.         frame_login.getContentPane().add(lblUsername);
  52.        
  53.         JLabel lblPassword = new JLabel("PASSWORD");
  54.         lblPassword.setFont(new Font("Verdana", Font.PLAIN, 12));
  55.         lblPassword.setBounds(33, 98, 102, 25);
  56.         frame_login.getContentPane().add(lblPassword);
  57.        
  58.         text_user = new JTextField();
  59.         text_user.setBounds(145, 50, 185, 36);
  60.         frame_login.getContentPane().add(text_user);
  61.         text_user.setColumns(10);
  62.        
  63.         text_pass = new JPasswordField();
  64.         text_pass.setBounds(145, 92, 185, 36);
  65.         frame_login.getContentPane().add(text_pass);
  66.        
  67.         btnLogIn = new JButton("LOG IN");
  68.         btnLogIn.addActionListener(new ActionListener() {
  69.             @SuppressWarnings("deprecation")
  70.             public void actionPerformed(ActionEvent e) {
  71.                 // Event Button Log In             
  72.                 try {
  73.                     us = text_user.getText();
  74.                     ps = text_pass.getText();
  75.                     SQL_LogIn = "SELECT * FROM user WHERE (user_id='"+us+"')AND(password='"+ps+"')";
  76.                     Connection c = Konek_DB.getKoneksi();              
  77.                     Statement s = c.createStatement();
  78.                     ResultSet r = s.executeQuery(SQL_LogIn);
  79.                     if(r.next()){
  80.                         //Log In Sukse
  81.                         JOptionPane.showMessageDialog(frame_login, "Welcome : "+us, "LOG IN", JOptionPane.INFORMATION_MESSAGE);
  82.                         Frame_Utama fut = new Frame_Utama();
  83.                         fut.frame_utama.setVisible(true);
  84.                         frame_login.dispose();
  85.                     }else{
  86.                         //Log In Gagal
  87.                         JOptionPane.showMessageDialog(frame_login, "Username atau Password Tidak Cocok", "LOG IN", JOptionPane.ERROR_MESSAGE);
  88.                         text_user.requestFocus();
  89.                     }
  90.                 } catch (SQLException e1) {
  91.                     JOptionPane.showMessageDialog(frame_login, e1.getMessage());
  92.                     System.exit(0);
  93.                 }
  94.                
  95.             }
  96.         });
  97.         btnLogIn.setFont(new Font("Verdana", Font.PLAIN, 12));
  98.         btnLogIn.setBounds(96, 144, 102, 36);
  99.         btnLogIn.setCursor(new Cursor(Cursor.HAND_CURSOR));
  100.         frame_login.getContentPane().add(btnLogIn);
  101.        
  102.         btnExit = new JButton("EXIT");
  103.         btnExit.addActionListener(new ActionListener() {
  104.             public void actionPerformed(ActionEvent arg0) {
  105.                 //Event Button Exit
  106.                 System.exit(0);
  107.             }
  108.         });
  109.         btnExit.setFont(new Font("Verdana", Font.PLAIN, 12));
  110.         btnExit.setBounds(217, 144, 102, 36);
  111.         btnExit.setCursor(new Cursor(Cursor.HAND_CURSOR));
  112.         frame_login.getContentPane().add(btnExit);
  113.        
  114.         pasTengah();
  115.     }
  116.    
  117.     private void pasTengah(){
  118.         //Posisi frame pas tengah
  119.         Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
  120.         int w = frame_login.getSize().width;
  121.         int h = frame_login.getSize().height;
  122.         int x = (dim.width-w)/2;
  123.         int y = (dim.height-h)/2;
  124.         frame_login.setLocation(x, y);
  125.     }
  126. }