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:
nah berikut adalah jframe interface hasil dari program diatas dibuat fullscreen yaitu menghilangkan atribut disudut atas yg berisi: tanda resize,tanda(x) dan tanda (-)
setelah itu masukkan nama pengguna dan sandi pengguna yang sudah anda tanam di program seperti contoh yang sudah saya tanam: nama pengguna(yohana) dan sandi (2002)

anda dapat masuk jika nama pengguna dan sandi pengguna yang anda ketikkan benar,jika hanya satu yang benar atau terdapat satu yang salah maka anda tidak dapat masuk karena pada program memakai fungsi equals (&&) ibaratnya itu sebagai pembanding. jika berhasil masuk maka akan tampil menu beranda seperti gambar dibawah ini:

jika anda menekan text box keluar maka akan tampil dialog box seperti gambar dibawah ini 


selanjutnya berikut adalah source code untuk beranda:

package latihan1kelasb;

import javax.swing.JFrame;

/**
 *
 * @author oryza
 */
public class Beranda extends javax.swing.JFrame {

    /**
     * Creates new form Beranda
     */
    public static String  test;

    public Beranda() {
        this.setExtendedState(JFrame.MAXIMIZED_BOTH);
        initComponents();
    }
    /**
     * 
     * @param nama
     * @return 
     */
//    public static void nama_umum(String nama){
//        test=nama;
//    }
    /**
     * 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();
        nama = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("SELAMAT DATANG");

        nama.setFont(new java.awt.Font("Gabriola", 1, 18)); // NOI18N
        nama.setText(test);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(150, 150, 150)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(nama, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(113, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(98, 98, 98)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(nama)
                .addContainerGap(96, Short.MAX_VALUE))
        );

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

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

        setJMenuBar(jMenuBar1);

        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(javax.swing.GroupLayout.Alignment.TRAILING, 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))
        );

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

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        //set variabel test dengan data yang dikirim dari 
        //form login baris ke 142
        test=args[0];
        /* 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(Beranda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Beranda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Beranda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Beranda.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 Beranda().setVisible(true);
                
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel nama;
    // End of variables declaration                   
}

penjelasan program diatas: nah program diatas adalah membuat beranda yaitu pertama kita awali dengan membuat jframe untuk dengan tampilan selamat datang (nama anda) anda dapat melihat di source code untuk menampilkan nama pengguna disimpan divariabel test yang ada di variabel dataku yang sebelumnya anda simpan juga di source code login.

berikut adalah hasil source code diatas jika di run kan.

Komentar

Postingan populer dari blog ini

Program Kasir dengan Bahasa Java

MEMBUAT PROGRAM KASIR SEDERHANA MENGGUNAKAN ARRAY DENGAN BAHASA JAVA

Program Kalkulator Sederhana Menggunakan Bahasa Java