Kaskus

Tech

donilaiAvatar border
TS
donilai
Login Multi User ke Aplikasi Utama JAVA SE
scrip From Login :
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package multiuser;
import conn.koneksi;
import koneksi.connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
/**
*
* @author D
*/
public class loginM extends javax.swing.JFrame {
koneksi koneksi;
Statement statement;
ResultSet resultSet;
public static int kondisiLogin=3;
public static String userLogin="tidak terdeteksi";
connection c;
/**
* Creates new form loginM
*/
public loginM() {
initComponents();
}
private void prosesLogin() {
String level = "";
try {
String sql = "select username,password,level from user where username='"
+ txtUser2.getText() +"' AND password = md5('"+txtPassword2.getText()+"' )";

statement = c.connect.createStatement();
resultSet = statement.executeQuery(sql);

while (resultSet.next()) {
level = resultSet.getString(3);
}
if (level.equals("")) {
JOptionPane.showMessageDialog(null, "USERNAME atau PASSWORD SALAH");
clear();
}
else {
if (level.equals("0")) {
new Menu_Utama().setVisible(true);
kondisiLogin = 0;

this.dispose();
} else if (level.equals("1")) {
new Menu_Utama().setVisible(true);
kondisiLogin = 1;
this.dispose();
} else {
new Menu_Utama().setVisible(true);
kondisiLogin = 3;
this.dispose();
}
userLogin = txtUser2.getText();
}

} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
private void clear(){
txtUser2.setText("");
txtPassword2.setText("");
}
/**
* 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() {

txtUser2 = new javax.swing.JTextField();
txtPassword2 = new javax.swing.JPasswordField();
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jButton1.setText("Login");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jLabel1.setText("User :");

jLabel2.setText("Password :");

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(47, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addGap(171, 171, 171))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(txtUser2, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addComponent(txtPassword2, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(95, 95, 95))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(71, 71, 71)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtUser2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtPassword2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addGap(18, 18, 18)
.addComponent(jButton1)
.addContainerGap(42, Short.MAX_VALUE))
);

pack();
}// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
prosesLogin();

}

/**
* @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 code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tu...feel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(loginM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(loginM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(loginM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(loginM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new loginM().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPasswordField txtPassword2;
private javax.swing.JTextField txtUser2;
// End of variables declaration
}

Scrip Menu Utama :
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package multiuser;
import java.sql.ResultSet;
import java.sql.Statement;
import conn.koneksi;

/**
*
* @author D
*/
public class Menu_Utama extends javax.swing.JFrame {
//koneksi koneksi;
public static int kodeLogin= 3 ;
ResultSet resultSet;
Statement statement;
public int login = 3;

/**
* Creates new form Menu_Utama
*/
public Menu_Utama() {
initComponents();
setLocationRelativeTo(null);

kodeLogin = login;
belumLogin();

if (login == 0) {
loginAdmin();
} else if (login == 1) {
loginKaryawan();
} else {
belumLogin();
}

}

Menu_Utama(int i) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}


private void belumLogin() {
jMenu2.setEnabled(false);
jMenu3.setEnabled(false);
jMenu4.setEnabled(false);
jMenu5.setVisible(true);
jMenu5.setEnabled(false);
subMenuLogin.setEnabled(true);
subMenuRegistrasi.setEnabled(false);
subMenuLogout.setEnabled(false);
}

private void loginAdmin() {
jMenu2.setEnabled(true);
jMenu3.setEnabled(true);
jMenu4.setEnabled(true);
jMenu5.setEnabled(true);
jMenu5.setVisible(true);
subMenuRegistrasi.setEnabled(true);
subMenuLogout.setEnabled(true);
subMenuLogin.setEnabled(false);
}

private void loginKaryawan() {
jMenu2.setEnabled(true);
jMenu3.setEnabled(true);
jMenu4.setEnabled(true);
jMenu5.setEnabled(true);
jMenu5.setVisible(false);
subMenuRegistrasi.setEnabled(false);
subMenuLogout.setEnabled(true);
subMenuLogin.setEnabled(false);
}


/**
* 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() {

jDialog1 = new javax.swing.JDialog();
jTextField1 = new javax.swing.JTextField();
jPasswordField1 = new javax.swing.JPasswordField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jDesktopPane1 = new javax.swing.JDesktopPane();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
subMenuLogin = new javax.swing.JMenuItem();
subMenuRegistrasi = new javax.swing.JMenuItem();
subMenuLogout = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jMenu3 = new javax.swing.JMenu();
jMenu4 = new javax.swing.JMenu();
jMenu5 = new javax.swing.JMenu();

jLabel1.setText("User Name : ");

jLabel2.setText("Password : ");

jButton1.setText("Login");

jButton2.setText("Batal");

javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
jDialog1.getContentPane().setLayout(jDialog1Layout);
jDialog1Layout.setHorizontalGroup(
jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDialog1Layout.createSequentialGroup()
.addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDialog1Layout.createSequentialGroup()
.addGap(54, 54, 54)
.addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDialog1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton1)
.addGap(18, 18, 18)
.addComponent(jButton2)))
.addContainerGap(68, Short.MAX_VALUE))
);
jDialog1Layout.setVerticalGroup(
jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDialog1Layout.createSequentialGroup()
.addGap(63, 63, 63)
.addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addGap(18, 18, 18)
.addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addGap(33, 33, 33)
.addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap(55, Short.MAX_VALUE))
);

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setPreferredSize(new java.awt.Dimension(1277, 770));

jDesktopPane1.setBackground(new java.awt.Color(0, 153, 204));

javax.swing.GroupLayout jDesktopPane1Layout = new javax.swing.GroupLayout(jDesktopPane1);
jDesktopPane1.setLayout(jDesktopPane1Layout);
jDesktopPane1Layout.setHorizontalGroup(
jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 550, Short.MAX_VALUE)
);
jDesktopPane1Layout.setVerticalGroup(
jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 368, Short.MAX_VALUE)
);

getContentPane().add(jDesktopPane1, java.awt.BorderLayout.CENTER);

jMenuBar1.setFocusTraversalPolicyProvider(true);

jMenu1.setText("File");

subMenuLogin.setText("Login");
subMenuLogin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
subMenuLoginActionPerformed(evt);
}
});
jMenu1.add(subMenuLogin);

subMenuRegistrasi.setText("Manajemen User");
subMenuRegistrasi.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
subMenuRegistrasiActionPerformed(evt);
}
});
jMenu1.add(subMenuRegistrasi);

subMenuLogout.setText("Logout");
jMenu1.add(subMenuLogout);

jMenuBar1.add(jMenu1);

jMenu2.setText("Edit");
jMenuBar1.add(jMenu2);

jMenu3.setText("jMenu3");
jMenuBar1.add(jMenu3);

jMenu4.setText("jMenu4");
jMenuBar1.add(jMenu4);

jMenu5.setText("jMenu5");
jMenuBar1.add(jMenu5);

setJMenuBar(jMenuBar1);

pack();
}// </editor-fold>

private void subMenuLoginActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
/* Mlogin mlogin = new Mlogin();
jDesktopPane1.add(mlogin);
mlogin.setVisible(true); */
loginM fs = new loginM();
fs.setVisible(true);
/* jDialog1.setSize(338, 230);
jDialog1.setLocationRelativeTo(null);
jDialog1.setVisible(true); */
// new tes().setVisible(true);
// dispose();
}

private void subMenuRegistrasiActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
manager_user mDua = new manager_user();
jDesktopPane1.add(mDua);
mDua.setVisible(true);

}

/**
* @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 code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tu...feel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Menu_Utama.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Menu_Utama.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Menu_Utama.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Menu_Utama.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
//new Menu_Utama().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JDesktopPane jDesktopPane1;
private javax.swing.JDialog jDialog1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenu jMenu5;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JTextField jTextField1;
private javax.swing.JMenuItem subMenuLogin;
private javax.swing.JMenuItem subMenuLogout;
private javax.swing.JMenuItem subMenuRegistrasi;
// End of variables declaration
}
Diubah oleh donilai 19-12-2018 11:13
0
4.5K
1
GuestAvatar border
Komentar yang asik ya
Mari bergabung, dapatkan informasi dan teman baru!
Programmer Forum
Programmer Forum
KASKUS Official
20.2KThread4.9KAnggota
Urutkan
Terlama
GuestAvatar border
Komentar yang asik ya
Ikuti KASKUS di
© 2025 KASKUS, PT Darta Media Indonesia. All rights reserved.