Membuat Form Login, Register dan Input Data kedalam Tabel menggunakan Java NetBeans tanpa Database
1. Deskripsi
Haloo gaes, kali ini saya akan memberikan tutorial sederhana cara membuat Form Login dan Register tanpa database menggunakan GUI Java NetBeans. Sebelum kita mulai disini saya akan memberikan sedikit deskripsi atau gambaran alur form nya... tampilan main menu awal saya buat pilihan masuk, ingin masuk dengan login atau masuk sebagai pengunjung. jika masuk sebagai pengunjung otomatis layar akan berpindah ke halaman beranda yang mana menampilkan pesan "Anda Berhasil Masuk".
Sebenarnya Tutorial ini masih kurang karena ada beberapa layar yang saya inginkan buat namun belum dapet ilhamnya... hahaha. cobain kuy :p
2. Project Tugas UTS
3. Flow Chart
4. Source Code dan Screen Shootnya...
SS layer main_menu
SS code layer Fmain_menu
- Source code
package JFrame;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
//@author Obung Amasy Azmatkhan
public class main_menu extends javax.swing.JFrame {
public main_menu() {
initComponents();
this.setLocationRelativeTo(null);//tampilan berada di posisi tengah layar
}
@SuppressWarnings("unchecked")
// <"Generated Code">
- event jFrame
this.setState(JFrame.ICONIFIED); //minimize layar }
private void jcloseMouseClicked(java.awt.event.MouseEvent evt) {
//memunculkan pesan konfirmasi keluar
int pesan = JOptionPane.showConfirmDialog(null, "keluar ?", "Konformasi",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (pesan == JOptionPane.YES_OPTION) {
System.exit(0);
}
}
private void BloginActionPerformed(java.awt.event.ActionEvent evt) {
Flogin log = new Flogin();
this.setVisible(false);
log.setVisible(true);
log.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void BtamuActionPerformed(java.awt.event.ActionEvent evt) {
Fberanda brd = new Fberanda();
this.setVisible(false);
brd.setVisible(true);
brd.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[]) {
- Element jFrame
// Variables declaration - do not modify
private javax.swing.JButton Blogin;
private javax.swing.JButton Btamu;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JLabel jclose;
private javax.swing.JLabel jmin;
// End of variables declaration
}
SS Layer Beranda
SS code layer Fberanda
- Source Code
package JFrame;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
/* @author Obung Amasy Azmatkhan */
public class Fberanda extends javax.swing.JFrame {
public Fberanda() {
initComponents();
this.setLocationRelativeTo(null);
}
@SuppressWarnings("unchecked")
// <"Generated Code">
- Event jFrame
private void BexitActionPerformed(java.awt.event.ActionEvent evt) {
int pesan = JOptionPane.showConfirmDialog(null, "Yakin ?", "Konformasi",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (pesan == JOptionPane.YES_OPTION) {
System.exit(0);
}
}
private void BmenuActionPerformed(java.awt.event.ActionEvent evt) {
main_menu main = new main_menu();
this.setVisible(false);
main.setVisible(true);
main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[]) {
- Element jFrame
// Variables declaration - do not modify
private javax.swing.JButton Bexit;
private javax.swing.JButton Bmenu;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
// End of variables declaration
}
SS layer Login
SS code Flogin
- Source Code
package JFrame;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
/*@author Obung Amasy Azmatkhan */
public class Flogin extends javax.swing.JFrame {
public Flogin() {
initComponents();
this.setLocationRelativeTo(null);
}
@SuppressWarnings("unchecked")
// <"Generated Code">
- Event Flogin
private void jlcloseMouseClicked(java.awt.event.MouseEvent evt) {
int pesan = JOptionPane.showConfirmDialog(null, "Yakin ?", "Konformasi",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (pesan == JOptionPane.YES_OPTION)
System.exit(0);
}
private void regisMouseClicked(java.awt.event.MouseEvent evt) {
Fregis reg = new Fregis();
reg.setVisible(true);
reg.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void BmasukActionPerformed(java.awt.event.ActionEvent evt) {
String user = "obung";
String pass = " ";
if (user.equalsIgnoreCase(Txuser.getText()) && pass.equals(Txpass.getText())) {
this.setVisible(false);
new Fberanda().setVisible(true);
} else if (pass.equals("")){
JOptionPane.showMessageDialog(null, "Password Salah !!");
Txpass.setText("");
Txpass.requestFocus();
}else {
JOptionPane.showMessageDialog(null, "User atau Password Salah !!");
Txuser.setText("");
Txpass.setText("");
Txuser.requestFocus();
}
}
private void BkembaliActionPerformed(java.awt.event.ActionEvent evt) {
int pesan = JOptionPane.showConfirmDialog(null, "Yakin ?", "Konformasi",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (pesan == JOptionPane.YES_OPTION) {
this.setVisible(false);
new main_menu().setVisible(true);
}
}
private void TxuserKeyPressed(java.awt.event.KeyEvent evt) {
if (evt.getKeyCode()== KeyEvent.VK_ENTER)
Txpass.requestFocus();
}
private void TxpassKeyPressed(java.awt.event.KeyEvent evt) {
if (evt.getKeyCode()== KeyEvent.VK_ENTER)
Bmasuk.doClick();
}
public static void main(String args[]) {
- Element Flogin
// Variables declaration - do not modify
private javax.swing.JButton Bkembali;
private javax.swing.JButton Bmasuk;
private javax.swing.JPasswordField Txpass;
private javax.swing.JTextField Txuser;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JLabel jlclose;
private javax.swing.JLabel regis;
// End of variables declaration
}
*Layer Bonus (belum fix)
SS Layer Registrasi
SS code Layer Fregis
- Source Code
package JFrame;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
/*@author Obung Amasy Azmatkhan */
public class Fregis extends javax.swing.JFrame {
int baris = 0;
static Object kolom[] = {"Nama", "User", "Pass", "Genre", "Ultah", "Domisili"};
DefaultTableModel simpan = new DefaultTableModel(kolom,baris);
public Fregis() {
initComponents();
this.setLocationRelativeTo(null);
Txnama.requestFocus();
}
@SuppressWarnings("unchecked")
// <"Generated Code">
- Event Fregis
private void closeMouseClicked(java.awt.event.MouseEvent evt) {
int pesan = JOptionPane.showConfirmDialog(null, "Yakin ?", "Konformasi",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
//muncul notif konfirmasi keluar
if (pesan == JOptionPane.YES_OPTION) {//jika pilih yes maka akan keluar aplikasi
System.exit(0);
}
}
private void TxnamaKeyPressed(java.awt.event.KeyEvent evt) {
if (evt.getKeyCode()== KeyEvent.VK_ENTER)
Txuser.requestFocus();
}
private void TxuserKeyPressed(java.awt.event.KeyEvent evt) {
if (evt.getKeyCode()== KeyEvent.VK_ENTER)
Txpass.requestFocus();
}
private void TxpassKeyPressed(java.awt.event.KeyEvent evt) {
if (evt.getKeyCode()== KeyEvent.VK_ENTER)
Txpass1.requestFocus();
}
private void Txpass1KeyPressed(java.awt.event.KeyEvent evt) {
if (evt.getKeyCode()== KeyEvent.VK_ENTER)
jrL.requestFocus(true);
}
private void jrLKeyPressed(java.awt.event.KeyEvent evt) {
if (evt.getKeyCode()== KeyEvent.VK_ENTER)
jrL.setSelected(true);
jdate.openPopup();
}
private void cBdomiKeyPressed(java.awt.event.KeyEvent evt) {
if (evt.getKeyCode()== KeyEvent.VK_ENTER)
Bbuat.doClick();
}
private void BbuatActionPerformed(java.awt.event.ActionEvent evt) {
String nama = Txnama.getText();
String user = Txuser.getText();
String pass = Txpass.getText();
String pass1 = Txpass1.getText();
Object genre = jrL.isSelected();
if (jrL.isSelected()) {
genre = jrL.getText();
}else if (jrP.isSelected()){
genre = jrP.getText();
}else {
genre = "";
}
Object date = jdate.getDate();
Object domi = cBdomi.getSelectedItem();
if(nama.equals("")){
JOptionPane.showMessageDialog(null, "Nama harus di isi");
Txnama.requestFocus();
}else if(user.equals("")){
JOptionPane.showMessageDialog(null, "User Name di butuhkan");
Txuser.requestFocus();
}else if(pass.equals("")){
JOptionPane.showMessageDialog(null, "Password tidak boleh kosong");
Txpass.requestFocus();
}else if(pass1.equals("") && pass1.equals(Txpass)){
JOptionPane.showMessageDialog(null, "Password tidak sama");
Txpass1.requestFocus();
}else if(genre.equals("")){
JOptionPane.showMessageDialog(null, "pilih Jenis Kelamin");
jrL.setSelected(true);
jrL.requestFocus();
}else if(date.equals("")){
JOptionPane.showMessageDialog(null, "Pilih Tanggal Lahir");
jdate.openPopup();
}else if(domi == cBdomi.getItemAt(0)){
JOptionPane.showMessageDialog(null, "pilih Tempat domisili");
cBdomi.isShowing();
}else {
simpan.addRow(new Object[] {nama, user, pass, genre, date, domi});
tuser.setModel(simpan);
Txnama.setText(null);
Txuser.setText(null);
Txpass.setText(null);
Txpass1.setText(null);
jrL.setSelected(false);
jrP.setSelected(false);
jdate.clear();
cBdomi.setSelectedIndex(0);
}
}
private void BbuatKeyPressed(java.awt.event.KeyEvent evt) {
if (evt.getKeyCode()== KeyEvent.VK_ENTER)
Bbuat.doClick();
}
private void jBresetActionPerformed(java.awt.event.ActionEvent evt) {
Txnama.setText(null);
Txuser.setText(null);
Txpass.setText(null);
Txpass1.setText(null);
jrL.setSelected(false);
jrP.setSelected(false);
jdate.clear();
cBdomi.setSelectedIndex(0);
}
private void BloginActionPerformed(java.awt.event.ActionEvent evt) {
Flogin log = new Flogin();
this.setVisible(false);
log.setVisible(true);
log.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void BeditActionPerformed(java.awt.event.ActionEvent evt) {
int baris_grid = tuser.getSelectedRow();
if (tuser.getSelectedRow() == 0){
JOptionPane.showMessageDialog(null, "pilih baris data yang akan dirubah");
}else {
int pesan = JOptionPane.showConfirmDialog(null, "Yakin ?", "Konformasi",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (pesan == JOptionPane.YES_OPTION) {
simpan.isCellEditable(baris_grid, baris_grid);
}
}
}
private void BhapusActionPerformed(java.awt.event.ActionEvent evt) {
int baris_grid = tuser.getSelectedRow();
if (baris_grid < 0){
JOptionPane.showMessageDialog(null, "pilih baris data yang akan dihapus");
tuser.setFocusable(rootPaneCheckingEnabled);
}else if(baris_grid == tuser.getSelectedRow()){
int pesan = JOptionPane.showConfirmDialog(null, "Yakin ?", "Konformasi",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (pesan == JOptionPane.YES_OPTION) {
simpan.removeRow(baris_grid);
}
}
}
public static void main(String args[]) {
- Element Fregis
// Variables declaration - do not modify
private javax.swing.JButton Bbuat;
private javax.swing.JButton Bedit;
private javax.swing.JButton Bhapus;
private javax.swing.JButton Blogin;
private javax.swing.JTextField Txnama;
private javax.swing.JPasswordField Txpass;
private javax.swing.JPasswordField Txpass1;
private javax.swing.JTextField Txuser;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.ButtonGroup buttonGroup2;
private javax.swing.JComboBox cBdomi;
private javax.swing.JLabel close;
private javax.swing.JButton jBreset;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel14;
private javax.swing.JLabel jLabel15;
private javax.swing.JLabel jLabel16;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JScrollPane jScrollPane1;
private com.github.lgooddatepicker.components.DatePicker jdate;
private javax.swing.JRadioButton jrL;
private javax.swing.JRadioButton jrP;
private javax.swing.JTable tuser;
// End of variables declaration
}
THANKS FOR READING MYBLOG
Tidak ada komentar:
Posting Komentar