Você está na página 1de 6

import java.sql.

*;
import java.sql.DriverManager;
import javax.swing.JOptionPane;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Asus
*/
public class LoginForm extends javax.swing.JFrame {
public String hak_akses="";
public String user_name="";
public LoginForm() {

initComponents();

}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel4 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
FieldUser = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
FieldPass = new javax.swing.JPasswordField();
jLabel5 = new javax.swing.JLabel();
ButtonLogin = new javax.swing.JButton();
ButtonCancel = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
ComboAkses1 = new javax.swing.JComboBox();
jLabel4.setText("jLabel4");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jLabel2.setText("User");
jLabel3.setText("Password");
jLabel5.setText("Akses");
ButtonLogin.setText("Login");
ButtonLogin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ButtonLoginActionPerformed(evt);
}
});
ButtonCancel.setText("Cancel");
ButtonCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ButtonCancelActionPerformed(evt);
}
});
jLabel1.setFont(new java.awt.Font("Calibri", 1, 24)); // NOI18N
jLabel1.setText("Login");
ComboAkses1.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
"Admin", "Manager", "Logistic", "Input" }));
ComboAkses1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ComboAkses1ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPan
el1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.
LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap(61, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLay
out.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel
1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.
GroupLayout.Alignment.LEADING, false)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING
, jPanel1Layout.createSequentialGroup()
.addComponent(jLabel5)
.addGap(49, 49, 49)
.addGroup(jPanel1Layout.createParallelGroup(java
x.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGrou
p()
.addComponent(ButtonLogin)
.addGap(52, 52, 52)
.addComponent(ButtonCancel)
.addGap(0, 25, Short.MAX_VALUE))
.addComponent(ComboAkses1, 0, javax.swing.Gr

oupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(java
x.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addGap(31, 31, 31)
.addGroup(jPanel1Layout.createParallelGroup(java
x.swing.GroupLayout.Alignment.LEADING)
.addComponent(FieldUser)
.addComponent(FieldPass))))
.addGap(84, 84, 84))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel
1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(171, 171, 171))))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.
LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(20, 20, 20)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLay
out.Alignment.BASELINE)
.addComponent(FieldUser, javax.swing.GroupLayout.PREFERRED_S
IZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZ
E)
.addComponent(jLabel2))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLay
out.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(FieldPass, javax.swing.GroupLayout.PREFERRED_S
IZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZ
E))
.addGap(21, 21, 21)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLay
out.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(ComboAkses1, javax.swing.GroupLayout.PREFERRED
_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_S
IZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLay
out.Alignment.BASELINE)
.addComponent(ButtonLogin)
.addComponent(ButtonCancel))
.addContainerGap(38, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentP
ane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createS
equentialGroup()
.addContainerGap(41, Short.MAX_VALUE)

.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, j
avax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(39, 39, 39))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(layout.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, j
avax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(32, Short.MAX_VALUE))
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>
private void ButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
}

// TODO add your handling code here:

private void ButtonLoginActionPerformed(java.awt.event.ActionEvent evt) {


String
String
String
String
String
String
try {

user="root";
pwd ="";
host="localhost";
db="dbERP";
urlValue;
hak_akses;

Class.forName("com.mysql.jdbc.Driver");
Connection conn = null;
conn=DriverManager.getConnection
("jdbc:mysql://localhost:3306/dbbap","root","");
if(conn!=null)
{
Statement st=conn.create
Statement();
ResultSet rs=st.executeQ
uery("SELECT * FROM tbluser WHERE nama_user='"+FieldUser.getText()+"' AND passwo
rd='"+FieldPass.getText()+"' AND hak_akses='"+ComboAkses1.getSelectedItem()+"'")
;
if(rs.next())
{
FormUtama tampil
=new FormUtama();
tampil.setVisible(true);
JOptionPane.show
MessageDialog(null,"Login Succes","Information",JOptionPane.INFORMATION_MESSAGE)
;
st.close();
conn.close();

}
else
{
JOptionPane.show
MessageDialog(null,"Login fail","Information",JOptionPane.INFORMATION_MESSAGE);
}
}
else
{
JOptionPane.showMessageD
ialog(null,"Error DB","Information",JOptionPane.INFORMATION_MESSAGE);
}
}
catch (SQLException e){
JOptionPane.showMessageDialog(null,"Login fail","Information",JO
ptionPane.INFORMATION_MESSAGE);
}
catch(ClassNotFoundException e) {
JOptionPane.showMessag
eDialog(null,"Class Database Not Found","Information",JOptionPane.INFORMATION_ME
SSAGE);
}
}
private void ComboAkses1ActionPerformed(java.awt.event.ActionEvent evt) {
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting cod
e (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the d
efault look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lo
okandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIMana
ger.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(LoginForm.class.getName()).log(ja
va.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(LoginForm.class.getName()).log(ja
va.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(LoginForm.class.getName()).log(ja
va.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(LoginForm.class.getName()).log(ja
va.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new LoginForm().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton ButtonCancel;
private javax.swing.JButton ButtonLogin;
private javax.swing.JComboBox ComboAkses1;
private javax.swing.JPasswordField FieldPass;
private javax.swing.JTextField FieldUser;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
// End of variables declaration
}

Você também pode gostar