package login;
import java.awt.Cursor;
public class Frame_Login {
public JFrame frame_login;
private JTextField text_user;
private JPasswordField text_pass;
private JButton btnLogIn,btnExit;
private String us,ps,SQL_LogIn;
public static void main(String[] args) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (ClassNotFoundException | InstantiationException
| IllegalAccessException | UnsupportedLookAndFeelException e1) {
System.exit(0);
}
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Frame_Login window = new Frame_Login();
window.frame_login.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public Frame_Login() {
initialize();
}
private void initialize() {
frame_login = new JFrame();
frame_login.getContentPane().setFont(new Font("Verdana", Font.PLAIN, 12));
frame_login.setBounds(100, 100, 394, 246);
frame_login.setTitle("Frame Log In");
frame_login.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame_login.setResizable(false);
frame_login.getContentPane().setLayout(null);
JLabel lblUsername = new JLabel("USERNAME");
lblUsername.setFont(new Font("Verdana", Font.PLAIN, 12));
lblUsername.setBounds(33, 56, 102, 25);
frame_login.getContentPane().add(lblUsername);
JLabel lblPassword = new JLabel("PASSWORD");
lblPassword.setFont(new Font("Verdana", Font.PLAIN, 12));
lblPassword.setBounds(33, 98, 102, 25);
frame_login.getContentPane().add(lblPassword);
text_user = new JTextField();
text_user.setBounds(145, 50, 185, 36);
frame_login.getContentPane().add(text_user);
text_user.setColumns(10);
text_pass = new JPasswordField();
text_pass.setBounds(145, 92, 185, 36);
frame_login.getContentPane().add(text_pass);
btnLogIn = new JButton("LOG IN");
btnLogIn.addActionListener(new ActionListener() {
@SuppressWarnings("deprecation")
public void actionPerformed(ActionEvent e) {
// Event Button Log In
try {
us = text_user.getText();
ps = text_pass.getText();
SQL_LogIn = "SELECT * FROM user WHERE (user_id='"+us+"')AND(password='"+ps+"')";
Connection c = Konek_DB.getKoneksi();
Statement s = c.createStatement();
ResultSet r = s.executeQuery(SQL_LogIn);
if(r.next()){
//Log In Sukse
JOptionPane.showMessageDialog(frame_login, "Welcome : "+us, "LOG IN", JOptionPane.INFORMATION_MESSAGE);
Frame_Utama fut = new Frame_Utama();
fut.frame_utama.setVisible(true);
frame_login.dispose();
}else{
//Log In Gagal
JOptionPane.showMessageDialog(frame_login, "Username atau Password Tidak Cocok", "LOG IN", JOptionPane.ERROR_MESSAGE);
text_user.requestFocus();
}
} catch (SQLException e1) {
JOptionPane.showMessageDialog(frame_login, e1.getMessage());
System.exit(0);
}
}
});
btnLogIn.setFont(new Font("Verdana", Font.PLAIN, 12));
btnLogIn.setBounds(96, 144, 102, 36);
btnLogIn.setCursor(new Cursor(Cursor.HAND_CURSOR));
frame_login.getContentPane().add(btnLogIn);
btnExit = new JButton("EXIT");
btnExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
//Event Button Exit
System.exit(0);
}
});
btnExit.setFont(new Font("Verdana", Font.PLAIN, 12));
btnExit.setBounds(217, 144, 102, 36);
btnExit.setCursor(new Cursor(Cursor.HAND_CURSOR));
frame_login.getContentPane().add(btnExit);
pasTengah();
}
private void pasTengah(){
//Posisi frame pas tengah
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
int w = frame_login.getSize().width;
int h = frame_login.getSize().height;
int x = (dim.width-w)/2;
int y = (dim.height-h)/2;
frame_login.setLocation(x, y);
}
}