program login dan beranda dengan bahasa java
PROGRAM LOGIN DAN BERANDA DENGAN BAHASA JAVA
halo semua kembali lagi diblok saya, kali ini saya akan membahas tentang bagimana cara membuat program login dan beranda dengan bahasa java.
berikut adalah sorce code nya unutk membuat program 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 latihan1kelasb;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
/**
*
* @author oryza
*/
public class Login extends javax.swing.JFrame {
/**
* Creates new form Login
*/
public Login() {
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setUndecorated(true);
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() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
nama_pengguna = new javax.swing.JTextField();
sandi_pengguna = new javax.swing.JTextField();
keluar = new javax.swing.JButton();
masuk = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setFont(new java.awt.Font("Dot Matrix", 1, 18)); // NOI18N
jLabel1.setText("Sandi Pengguna");
jLabel2.setFont(new java.awt.Font("Dot Matrix", 1, 18)); // NOI18N
jLabel2.setText("Nama Pengguna");
keluar.setText("Keluar");
keluar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
keluarActionPerformed(evt);
}
});
masuk.setText("Masuk");
masuk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
masukActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(36, 36, 36)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(28, 28, 28)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(sandi_pengguna, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)
.addComponent(nama_pengguna))
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(keluar, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(masuk, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(61, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(3, 3, 3)
.addComponent(nama_pengguna, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(sandi_pengguna, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(27, 27, 27)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(masuk, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(keluar, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(69, 69, 69))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void keluarActionPerformed(java.awt.event.ActionEvent evt) {
kotak_pesan();
// System.exit(0);
// TODO add your handling code here:
}
private void masukActionPerformed(java.awt.event.ActionEvent evt) {
String dataku[]=new String [2];
dataku[0]="yohana";
dataku[1]="2002";
//"yohana",sandi="2002";
if(dataku[0].equals(nama_pengguna.getText())&&dataku[1].equals(sandi_pengguna.getText()))
{
Beranda masa_depan=new Beranda();//Membuat Instant dari kelas Beranda
masa_depan.main(dataku);//Menyimpan data dari array dataku ke method main pada kelas beranda
masa_depan.setVisible(true);//Menampilkan kelas beranda
this.dispose();//Menutup kelas Login
}
// TODO add your handling code here:
}
/**
* @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/tutorial/uiswing/lookandfeel/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(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Login.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 Login().setVisible(true);
}
});
}
/**
* Kotak Pesan
* Created TIF1B
*/
public void kotak_pesan(){
int dialogButton = JOptionPane.showConfirmDialog (null, "Apakah Anda Yakin Akan Keluar?","PERINGATAN",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
if(dialogButton == JOptionPane.YES_OPTION) {
System.exit(0);}
}
/**
* Kotak Pesan
* Created TIF1B
*/
public void kotak_pesan_login(){
int dialogButton = JOptionPane.showConfirmDialog (null, "Nama Pengguna Atau Sandi Salah?","PERINGATAN",JOptionPane.WARNING_MESSAGE);
}
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JButton keluar;
private javax.swing.JButton masuk;
private javax.swing.JTextField nama_pengguna;
private javax.swing.JTextField sandi_pengguna;
// End of variables declaration
}
penjelasan dari source code diatas: program diatas dimulai dengan dengan membuat nama kelas yaitu class login selanjutnya mendesain jframe untuk menu login pertama kali, nah jframe nya nanti dibuat berisi nama pengguna dan kata sandi anda dapat mendesain jframe nya sesuai keinginan anda dengan fitur pallete setelah itu selanjutnya anda mengedit nya dengan klik kanan lalu edit text dan setalah itu klik kanan selanjutnya kita memasukkan program untuk jframe tadi program diatas memakai array untuk menyimpan data nama pengguna dan kata sandi atau password, nama pengguna dan password disini dapat anda atur sendiri sesuka hati anda contoh nya saya membuat nama pengguna: yohana dan kata sandi: 2002, perhatikan dengan teliti penggunaan huruf kapital atau tidak yang anda pakai karna itu sangat berpengaruh. nah selanjutnya saya akan menjelaskan source code untuk jframe nya ada dua text box yaitu masuk dan keluar didalam texst box masuk dimasukkan kodingan sebagaimaana contoh source code diatas selanjutnya text box keluar juga dimasukkan source code seperti diatas jika anda menekan text box keluar maka akan muncul dialog box "apakah anda yakin keluar?" (gambar akan saya tampilkan dibawah) selanjutnya jika anda menekan text box masuk maka anda akan langsung terganti ke menu jframe beranda lalu akan muncul selamat datang yohana.
berikut adalah hasil dari program diatas:sekian penjelasan program diatas, jika ada penjelasan yang kurang dimengerti saya mohon maaf terimakasih;) (btw warna teksnya emang biru hehe)
Komentar
Posting Komentar