Rabu, 14 November 2012

Membuat Interface Sistem Toko Buku dengan Netbeans 7.1.2

Form Buku

source code:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tokobuku;

/**
 *
 * @author ALvin
 */
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.table.DefaultTableModel;
public class Buku extends javax.swing.JFrame {

    /**
     * Creates new form Buku
     */
    String id_buku;
    Connection conn;
    String[] judul={"ID Buku","Judul Buku","Pengarang","Harga","Kategori","Stock"};
    DefaultTableModel def = new DefaultTableModel(null,judul);
    public Buku() {
        initComponents();
        tblBuku.setModel(def);
        tampil();
    }
     public void tampil(){
             try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tokobuku","root","713");
Statement stmt;
                stmt = conn.createStatement();
                ResultSet rs =stmt.executeQuery("select * from buku order by id_buku");
             while(rs.next())
             {
                String id_buku = rs.getString("id_buku");
                String judul_buku = rs.getString("judul_buku");
                String pengarang = rs.getString("pengarang");
                String harga = rs.getString("harga");
                String kategori = rs.getString("kategori");
                String stock = rs.getString("stock");
                String[] data = {id_buku, judul_buku, pengarang, harga, kategori, stock };
                def.addRow(data);
            }      
} catch (Exception exc) {
System.out.println("JDBC Driver,tidak ditemukan atau rusak :: " + exc);
}  
    }

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

        jLabel1 = new javax.swing.JLabel();
        txtIdBuku = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtJudulBuku = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtPengarang = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtHarga = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtKategori = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtStock = new javax.swing.JTextField();
        btnHapus = new javax.swing.JButton();
        btnEdit = new javax.swing.JButton();
        btnSimpan = new javax.swing.JButton();
        btnBatal = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblBuku = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("ID Buku:");

        txtIdBuku.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtIdBukuActionPerformed(evt);
            }
        });

        jLabel2.setText("Judul Buku:");

        jLabel3.setText("Pengarang:");

        jLabel4.setText("Harga:");

        jLabel5.setText("Kategori:");

        jLabel6.setText("Stock:");

        btnHapus.setText("Hapus");
        btnHapus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHapusActionPerformed(evt);
            }
        });

        btnEdit.setText("Edit");
        btnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditActionPerformed(evt);
            }
        });

        btnSimpan.setText("Simpan");
        btnSimpan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSimpanActionPerformed(evt);
            }
        });

        btnBatal.setText("Batal");
        btnBatal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBatalActionPerformed(evt);
            }
        });

        tblBuku.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tblBuku);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(24, 24, 24)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel1))
                                .addGap(25, 25, 25)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(txtIdBuku, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(txtPengarang)
                                        .addComponent(txtHarga, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(txtKategori)
                                        .addComponent(txtJudulBuku, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(txtStock, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(129, 129, 129)
                                .addComponent(btnSimpan)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnHapus)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnEdit)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnBatal)))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 646, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtIdBuku, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtJudulBuku, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtPengarang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtHarga, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtKategori, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtStock, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnHapus)
                    .addComponent(btnEdit)
                    .addComponent(btnSimpan)
                    .addComponent(btnBatal))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 213, Short.MAX_VALUE)
                .addContainerGap())
        );

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

    private void btnSimpanActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        try {
                String id_buku = txtIdBuku.getText();
                String judul_buku = txtJudulBuku.getText();
                String pengarang = txtPengarang.getText();
                String harga = txtHarga.getText();
                String kategori = txtKategori.getText();
                String stock = txtStock.getText();
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tokobuku","root","713");
Statement stmt;
                stmt = conn.createStatement();
                stmt.executeUpdate("insert into buku values('"+id_buku+"','"+judul_buku+"','"+pengarang+"','"+harga+"','"+kategori+"','"+stock+"')");
                JOptionPane.showMessageDialog(null, "Data berhasil di simpan");
                txtIdBuku.setText("");
                txtJudulBuku.setText("");
                txtPengarang.setText("");
                txtHarga.setText("");
                txtKategori.setText("");
                txtStock.setText("");
                hapusdatatabel();          
                tampil();
                conn.close();              
} catch (Exception exc) {
System.out.println("JDBC Driver,tidak ditemukan atau rusak :: " + exc);
}
    }                                      

    private void txtIdBukuActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        try {
                String id_buku = txtIdBuku.getText();
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tokobuku","root","713");
Statement stmt;
                stmt = conn.createStatement();
                ResultSet rs =stmt.executeQuery("select * from buku where id_buku like'"+id_buku+"'");
             if(rs.next())
             {
                     JOptionPane.showMessageDialog(null, "Data di temukan");
                     txtIdBuku.setText(rs.getString("id_buku"));
                     txtJudulBuku.setText(rs.getString("judul_buku"));
                     txtPengarang.setText(rs.getString("pengarang"));
                     txtHarga.setText(rs.getString("harga"));
                     txtKategori.setText(rs.getString("kategori"));
                     txtStock.setText(rs.getString("stock"));
             }
             else{
            JOptionPane.showMessageDialog(null, "Data tidak di temukan");
                     txtIdBuku.setText("");
                     txtJudulBuku.setText("");
                     txtPengarang.setText("");
                     txtHarga.setText("");
                     txtKategori.setText("");
                     txtStock.setText("");
            }      
} catch (Exception exc) {
System.out.println("JDBC Driver,tidak ditemukan atau rusak :: " + exc);
}
    }                                      

    private void btnHapusActionPerformed(java.awt.event.ActionEvent evt) {                                      
        // TODO add your handling code here:
        try {
                String id_buku = txtIdBuku.getText();
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tokobuku","root","713");
Statement stmt;
                stmt = conn.createStatement();
                stmt.executeUpdate("delete from buku where id_buku like '"+id_buku+"'");
                JOptionPane.showMessageDialog(null, "Data berhasil di hapus");
                txtIdBuku.setText("");
                txtJudulBuku.setText("");
                txtPengarang.setText("");
                txtHarga.setText("");
                txtKategori.setText("");
                txtStock.setText("");
                hapusdatatabel();
                tampil();
                conn.close();
} catch (Exception exc) {
System.out.println("JDBC Driver,tidak ditemukan atau rusak :: " + exc);
}
    }                                      

    private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {                                      
        // TODO add your handling code here:
        try {
                String id_buku = txtIdBuku.getText();
                String judul_buku = txtJudulBuku.getText();
                String pengarang = txtPengarang.getText();
                String harga = txtHarga.getText();
                String kategori = txtKategori.getText();
                String stock = txtStock.getText();
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tokobuku","root","713");
Statement stmt;
                stmt = conn.createStatement();
             
                stmt.executeUpdate("update  buku set judul_buku='"+judul_buku+"',pengarang= '"+pengarang+"', harga = '"+harga+"',kategori = '"+kategori+"',stock = '"+stock+"' where id_buku = '"+id_buku+"'");
                JOptionPane.showMessageDialog(null, "Data berhasil di update");
                txtIdBuku.setText("");
                txtJudulBuku.setText("");
                txtPengarang.setText("");
                txtHarga.setText("");
                txtKategori.setText("");
                txtStock.setText("");
                hapusdatatabel();
                tampil();
                conn.close();
} catch (Exception exc) {
System.out.println("JDBC Driver,tidak ditemukan atau rusak :: " + exc);
}
    }                                    

    private void btnBatalActionPerformed(java.awt.event.ActionEvent evt) {                                      
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(null, "Data berhasil di reset");
                txtIdBuku.setText("");
                txtJudulBuku.setText("");
                txtPengarang.setText("");
                txtHarga.setText("");
                txtKategori.setText("");
                txtStock.setText("");
                hapusdatatabel();
                tampil();
    }                                      

    /**
     * @param args the command line arguments
     */
     public void hapusdatatabel(){
        int row= def.getRowCount();
     
        for (int i = 0; i<row; i++)
        {
            def.removeRow(0);
         
        }
    }
    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(Buku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Buku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Buku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Buku.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 Buku().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                  
    private javax.swing.JButton btnBatal;
    private javax.swing.JButton btnEdit;
    private javax.swing.JButton btnHapus;
    private javax.swing.JButton btnSimpan;
    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.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblBuku;
    private javax.swing.JTextField txtHarga;
    private javax.swing.JTextField txtIdBuku;
    private javax.swing.JTextField txtJudulBuku;
    private javax.swing.JTextField txtKategori;
    private javax.swing.JTextField txtPengarang;
    private javax.swing.JTextField txtStock;
    // End of variables declaration                
}

Form Supplier

source code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tokobuku;

/**
 *
 * @author ALvin
 */
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.table.DefaultTableModel;
public class Supplier extends javax.swing.JFrame {

    /**
     * Creates new form Supplier
     */
    String id_supplier;
    Connection conn;
    String[] judul={"ID Supplier","Nama Supplier","Alamat","No Telepon"};
    DefaultTableModel def = new DefaultTableModel(null,judul);
    public Supplier() {
        initComponents();
        tblSupplier.setModel(def);
        tampil();
    }
    public void tampil(){
             try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tokobuku","root","713");
Statement stmt;
                stmt = conn.createStatement();
                ResultSet rs =stmt.executeQuery("select * from supplier order by id_supplier");
             while(rs.next())
             {
                String id_supplier = rs.getString("id_supplier");
                String nama_supplier = rs.getString("nama_supplier");
                String alamat = rs.getString("alamat");
                String no_tlpn = rs.getString("no_tlpn");
                String[] data = {id_supplier, nama_supplier, alamat, no_tlpn};
                def.addRow(data);
            }        
} catch (Exception exc) {
System.out.println("JDBC Driver,tidak ditemukan atau rusak :: " + exc);  
}    
    }
    /**
     * 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() {

        jLabel1 = new javax.swing.JLabel();
        txtIDSupplier = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtNamaSupplier = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtAlamat = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtNoTelepon = new javax.swing.JTextField();
        btnSimpan = new javax.swing.JButton();
        btnEdit = new javax.swing.JButton();
        btnHapus = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblSupplier = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("ID Supplier:");

        txtIDSupplier.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtIDSupplierActionPerformed(evt);
            }
        });

        jLabel2.setText("Nama Supplier:");

        jLabel3.setText("Alamat:");

        jLabel4.setText("No. Telepon:");

        btnSimpan.setText("Simpan");
        btnSimpan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSimpanActionPerformed(evt);
            }
        });

        btnEdit.setText("Edit");
        btnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditActionPerformed(evt);
            }
        });

        btnHapus.setText("Hapus");
        btnHapus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHapusActionPerformed(evt);
            }
        });

        tblSupplier.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tblSupplier);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addGap(37, 37, 37)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(btnSimpan)
                                .addGap(18, 18, 18)
                                .addComponent(btnEdit)
                                .addGap(18, 18, 18)
                                .addComponent(btnHapus))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(txtNamaSupplier, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)
                                .addComponent(txtAlamat))
                            .addComponent(txtNoTelepon, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtIDSupplier, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(15, Short.MAX_VALUE)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 407, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(50, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtIDSupplier, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtNamaSupplier, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtAlamat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtNoTelepon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSimpan)
                    .addComponent(btnEdit)
                    .addComponent(btnHapus))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

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

    private void btnSimpanActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        try {
                String id_supplier = txtIDSupplier.getText();
                String nama_supplier = txtNamaSupplier.getText();
                String alamat = txtAlamat.getText();
                String no_tlpn = txtNoTelepon.getText();
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tokobuku","root","713");
Statement stmt;
                stmt = conn.createStatement();
                stmt.executeUpdate("insert into supplier values('"+id_supplier+"','"+nama_supplier+"','"+alamat+"','"+no_tlpn+"')");
                JOptionPane.showMessageDialog(null, "Data berhasil di simpan");
                txtIDSupplier.setText("");
                txtNamaSupplier.setText("");
                txtAlamat.setText("");
                txtNoTelepon.setText("");
                hapusdatatabel();            
                tampil();
                conn.close();                
} catch (Exception exc) {
System.out.println("JDBC Driver,tidak ditemukan atau rusak :: " + exc);  
}
    }                                         

    private void txtIDSupplierActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
        try {
                String id_supplier = txtIDSupplier.getText();
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tokobuku","root","713");
Statement stmt;
                stmt = conn.createStatement();
                ResultSet rs =stmt.executeQuery("select * from supplier where id_supplier like'"+id_supplier+"'");
             if(rs.next())
             {
                     JOptionPane.showMessageDialog(null, "Data di temukan");
                     txtIDSupplier.setText(rs.getString("id_supplier"));
                     txtNamaSupplier.setText(rs.getString("nama_supplier"));
                     txtAlamat.setText(rs.getString("alamat"));
                     txtNoTelepon.setText(rs.getString("no_tlpn"));
             }  
             else{
            JOptionPane.showMessageDialog(null, "Data tidak di temukan");
                     txtIDSupplier.setText("");
                     txtNamaSupplier.setText("");
                     txtAlamat.setText("");
                     txtNoTelepon.setText("");
            }        
} catch (Exception exc) {
System.out.println("JDBC Driver,tidak ditemukan atau rusak :: " + exc);  
}
    }                                             

    private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        try {
                String id_supplier = txtIDSupplier.getText();
                String nama_supplier = txtNamaSupplier.getText();
                String alamat = txtAlamat.getText();
                String no_tlpn = txtNoTelepon.getText();
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/db_kafe","root","713");
Statement stmt;
                stmt = conn.createStatement();
                
                stmt.executeUpdate("update  supplier set nama_supplier='"+nama_supplier+"',alamat= '"+alamat+"', no_tlpn = '"+no_tlpn+"' where id_supplier = '"+id_supplier+"'");
                JOptionPane.showMessageDialog(null, "Data berhasil di update");
                txtIDSupplier.setText("");
                txtNamaSupplier.setText("");
                txtAlamat.setText("");
                txtNoTelepon.setText("");
                hapusdatatabel();
                tampil();
                conn.close();
} catch (Exception exc) {
System.out.println("JDBC Driver,tidak ditemukan atau rusak :: " + exc);  
}
    }                                       

    private void btnHapusActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        try {
                String id_supplier = txtIDSupplier.getText();
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tokobuku","root","713");
Statement stmt;
                stmt = conn.createStatement();
                stmt.executeUpdate("delete from supplier where id_supplier like '"+id_supplier+"'");
                JOptionPane.showMessageDialog(null, "Data berhasil di hapus");
                txtIDSupplier.setText("");
                txtNamaSupplier.setText("");
                txtAlamat.setText("");
                txtNoTelepon.setText("");
                hapusdatatabel();
                tampil();
                conn.close(); 
} catch (Exception exc) {
System.out.println("JDBC Driver,tidak ditemukan atau rusak :: " + exc);  
}
    }                                        

    /**
     * @param args the command line arguments
     */
    public void hapusdatatabel(){
        int row= def.getRowCount();
        
        for (int i = 0; i<row; i++)
        {
            def.removeRow(0);
            
        }
    }
    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(Supplier.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Supplier.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Supplier.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Supplier.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 Supplier().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JButton btnEdit;
    private javax.swing.JButton btnHapus;
    private javax.swing.JButton btnSimpan;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblSupplier;
    private javax.swing.JTextField txtAlamat;
    private javax.swing.JTextField txtIDSupplier;
    private javax.swing.JTextField txtNamaSupplier;
    private javax.swing.JTextField txtNoTelepon;
    // End of variables declaration                   
}

Form Pegawai
Source Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tokobuku;

/**
 *
 * @author ALvin
 */
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.table.DefaultTableModel;
public class Pegawai extends javax.swing.JFrame {

    /**
     * Creates new form Pegawai
     */
    String id_pegawai;
    Connection conn;
    String[] judul={"ID Pegawai","Nama Pegawai","Alamat","Gender","No Telepon"};
    DefaultTableModel def = new DefaultTableModel(null,judul);
    public Pegawai() {
        initComponents();
        tblPegawai.setModel(def);
        tampil();
    }
    public void tampil(){
             try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tokobuku","root","713");
Statement stmt;
                stmt = conn.createStatement();
                ResultSet rs =stmt.executeQuery("select * from pegawai order by id_pegawai");
             while(rs.next())
             {
                String id_pegawai = rs.getString("id_pegawai");
                String nama_pegawai = rs.getString("nama_pegawai");
                String alamat = rs.getString("alamat");
                String gender = rs.getString("gender");
                String no_tlpn = rs.getString("no_tlpn");
                String[] data = {id_pegawai, nama_pegawai, alamat, gender, no_tlpn };
                def.addRow(data);
            }        
} catch (Exception exc) {
System.out.println("JDBC Driver,tidak ditemukan atau rusak :: " + exc);  
}    
    }
    /**
     * 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() {

        jLabel1 = new javax.swing.JLabel();
        txtIdPegawai = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtNamaPegawai = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtAlamat = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtGender = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtNoTelepon = new javax.swing.JTextField();
        btnSimpan = new javax.swing.JButton();
        btnEdit = new javax.swing.JButton();
        btnHapus = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblPegawai = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("ID Pegawai:");

        txtIdPegawai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtIdPegawaiActionPerformed(evt);
            }
        });

        jLabel2.setText("Nama Pegawai:");

        jLabel3.setText("Alamat:");

        jLabel4.setText("Gender:");

        jLabel5.setText("No Telepon:");

        btnSimpan.setText("Simpan");
        btnSimpan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSimpanActionPerformed(evt);
            }
        });

        btnEdit.setText("Edit");
        btnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditActionPerformed(evt);
            }
        });

        btnHapus.setText("Hapus");
        btnHapus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHapusActionPerformed(evt);
            }
        });

        tblPegawai.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tblPegawai);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(27, 27, 27)
                                .addComponent(jLabel1))
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel5))))
                        .addGap(33, 33, 33)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(btnSimpan)
                                .addGap(27, 27, 27)
                                .addComponent(btnEdit)
                                .addGap(29, 29, 29)
                                .addComponent(btnHapus))
                            .addComponent(txtIdPegawai, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtNamaPegawai, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtAlamat, javax.swing.GroupLayout.PREFERRED_SIZE, 264, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtGender, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtNoTelepon, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 519, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(54, 54, 54)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtIdPegawai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtNamaPegawai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtAlamat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtGender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(txtNoTelepon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSimpan)
                    .addComponent(btnEdit)
                    .addComponent(btnHapus))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
                .addContainerGap())
        );

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

    private void btnSimpanActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
         try {
                String id_pegawai = txtIdPegawai.getText();
                String nama_pegawai = txtNamaPegawai.getText();
                String alamat = txtAlamat.getText();
                String gender = txtGender.getText();
                String no_tlpn = txtNoTelepon.getText();
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tokobuku","root","713");
Statement stmt;
                stmt = conn.createStatement();
                stmt.executeUpdate("insert into buku values('"+id_pegawai+"','"+nama_pegawai+"','"+alamat+"','"+gender+"','"+no_tlpn+"')");
                JOptionPane.showMessageDialog(null, "Data berhasil di simpan");
                txtIdPegawai.setText("");
                txtNamaPegawai.setText("");
                txtAlamat.setText("");
                txtGender.setText("");
                txtNoTelepon.setText("");
                hapusdatatabel();            
                tampil();
                conn.close();                
} catch (Exception exc) {
System.out.println("JDBC Driver,tidak ditemukan atau rusak :: " + exc);  
}
    }                                         

    private void txtIdPegawaiActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
        try {
                String id_pegawai = txtIdPegawai.getText();
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tokobuku","root","713");
Statement stmt;
                stmt = conn.createStatement();
                ResultSet rs =stmt.executeQuery("select * from pegawai where id_pegawai like'"+id_pegawai+"'");
             if(rs.next())
             {
                     JOptionPane.showMessageDialog(null, "Data di temukan");
                     txtIdPegawai.setText(rs.getString("id_buku"));
                     txtNamaPegawai.setText(rs.getString("nama_pegawai"));
                     txtAlamat.setText(rs.getString("alamat"));
                     txtGender.setText(rs.getString("Gender"));
                     txtNoTelepon.setText(rs.getString("no_tlpn"));
            }
            else{
            JOptionPane.showMessageDialog(null, "Data tidak di temukan");
                     txtIdPegawai.setText("");
                     txtNamaPegawai.setText("");
                     txtAlamat.setText("");
                     txtGender.setText("");
                     txtNoTelepon.setText("");
            }        
} catch (Exception exc) {
System.out.println("JDBC Driver,tidak ditemukan atau rusak :: " + exc);  
}
    }                                            

    private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
         try {
                String id_pegawai = txtIdPegawai.getText();
                String nama_pegawai = txtNamaPegawai.getText();
                String alamat = txtAlamat.getText();
                String Gender = txtGender.getText();
                String no_tlpn = txtNoTelepon.getText();
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tokobuku","root","713");
Statement stmt;
                stmt = conn.createStatement();
                
                stmt.executeUpdate("update  pegawai set nama_pegawai='"+nama_pegawai+"',alamat= '"+alamat+"', Gender = '"+Gender+"',no_tlpn = '"+no_tlpn+"' where id_pegawai = '"+id_pegawai+"'");
                JOptionPane.showMessageDialog(null, "Data berhasil di update");
                txtIdPegawai.setText("");
                txtNamaPegawai.setText("");
                txtAlamat.setText("");
                txtGender.setText("");
                txtNoTelepon.setText("");
                hapusdatatabel();
                tampil();
                conn.close();
} catch (Exception exc) {
System.out.println("JDBC Driver,tidak ditemukan atau rusak :: " + exc);  
}
    }                                       

    private void btnHapusActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        try {
                String id_pegawai = txtIdPegawai.getText();
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tokobuku","root","713");
Statement stmt;
                stmt = conn.createStatement();
                stmt.executeUpdate("delete from pegawai where id_pegawai like '"+id_pegawai+"'");
                JOptionPane.showMessageDialog(null, "Data berhasil di hapus");
                txtIdPegawai.setText("");
                txtNamaPegawai.setText("");
                txtAlamat.setText("");
                txtGender.setText("");
                txtNoTelepon.setText("");
                hapusdatatabel();
                tampil();
                conn.close(); 
} catch (Exception exc) {
System.out.println("JDBC Driver,tidak ditemukan atau rusak :: " + exc);  
}
    }                                        

    /**
     * @param args the command line arguments
     */
    public void hapusdatatabel(){
        int row= def.getRowCount();
        
        for (int i = 0; i<row; i++)
        {
            def.removeRow(0);
            
        }
    }
    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(Pegawai.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Pegawai.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Pegawai.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Pegawai.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 Pegawai().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JButton btnEdit;
    private javax.swing.JButton btnHapus;
    private javax.swing.JButton btnSimpan;
    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.JScrollPane jScrollPane1;
    private javax.swing.JTable tblPegawai;
    private javax.swing.JTextField txtAlamat;
    private javax.swing.JTextField txtGender;
    private javax.swing.JTextField txtIdPegawai;
    private javax.swing.JTextField txtNamaPegawai;
    private javax.swing.JTextField txtNoTelepon;
    // End of variables declaration                   
}

Form Struk Pembayaran















Source Code:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tokobuku;

/**
 *
 * @author ALvin
 */
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.table.DefaultTableModel;
public class Struk_Pembayaran extends javax.swing.JFrame {

    /**
     * Creates new form Struk_Pembayaran
     */
    int total_harga;
    String id_buku;
    
    Connection conn;
    String[] judul={"ID Buku","Judul Buku","Pengarang","Harga","Kategori","Stock"};
    DefaultTableModel def = new DefaultTableModel(null,judul);
    String[] judul1={"No Struk","Tanggal","Total Harga","Jumlah Buku","ID Buku"};
    DefaultTableModel def1 = new DefaultTableModel(null,judul1);
    public Struk_Pembayaran() {
        initComponents();
        tblBuku.setModel(def);
        tampil1();
        tblStruk_Pembayaran.setModel(def1);
        tampil2();
    }
    public void tampil1(){
             try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tokobuku","root","713");
Statement stmt;
                stmt = conn.createStatement();
                ResultSet rs =stmt.executeQuery("select * from buku order by id_buku");
             while(rs.next())
             {
                String id_buku = rs.getString("id_buku");
                String judul_buku = rs.getString("judul_buku");
                String pengarang = rs.getString("pengarang");
                String harga = rs.getString("harga");
                String kategori = rs.getString("kategori");
                String stock = rs.getString("stock");
                String[] data = {id_buku, judul_buku, pengarang, harga, kategori, stock };
                def.addRow(data);
            }        
} catch (Exception exc) {
System.out.println("JDBC Driver,tidak ditemukan atau rusak :: " + exc);  
}    
    }
    public void tampil2(){
        
             try {
                
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tokobuku","root","713");
Statement stmt;
                stmt = conn.createStatement();
                ResultSet rs =stmt.executeQuery("select * from struk_pembayaran");
                while(rs.next())
             {
                String no_struk = rs.getString("no_struk");
                String tanggal = rs.getString("tanggal");
                String total_harga = rs.getString("total_harga");
                String jumlah_buku = rs.getString("jumlah_buku");
                String id_buku = rs.getString("id_buku");
                String[] data = {no_struk, tanggal, total_harga, jumlah_buku, id_buku};
                def1.addRow(data);
            }
            
                
} catch (Exception exc) {
System.out.println("JDBC Driver,tidak ditemukan atau rusak :: " + exc);  
}
        
    }
    /**
     * 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() {

        jLabel1 = new javax.swing.JLabel();
        txtNoStruk = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtTanggal = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtJumlahBuku = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtHarga = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtIdBuku = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtJudulBuku = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblBuku = new javax.swing.JTable();
        btnInput = new javax.swing.JButton();
        btnBatal = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblStruk_Pembayaran = new javax.swing.JTable();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        txtTotalHarga = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("No Struk:");

        jLabel2.setText("Tanggal:");

        jLabel3.setText("Jumlah Buku:");

        jLabel4.setText("Harga:");

        jLabel5.setText("ID Buku:");

        jLabel6.setText("Judul Buku:");

        tblBuku.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tblBuku);

        btnInput.setText("Input");
        btnInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInputActionPerformed(evt);
            }
        });

        btnBatal.setText("Batal");
        btnBatal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBatalActionPerformed(evt);
            }
        });

        tblStruk_Pembayaran.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(tblStruk_Pembayaran);

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel7.setText("Tabel Buku");

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel8.setText("Tabel Struk Pembayaran");

        jLabel10.setText("Total Harga");

        txtTotalHarga.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtTotalHargaActionPerformed(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel9.setText("Form Struk Pembayaran");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(544, 544, 544)
                        .addComponent(jLabel7))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel1)
                                .addComponent(jLabel2)))
                        .addGap(33, 33, 33)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(btnInput)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(btnBatal))
                                        .addComponent(txtHarga, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(txtJumlahBuku, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE)
                                            .addComponent(txtIdBuku, javax.swing.GroupLayout.Alignment.LEADING))
                                        .addComponent(txtJudulBuku, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(txtTanggal, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtNoStruk, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 561, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtTotalHarga, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING))
                                .addGap(54, 54, 54)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 602, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(19, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addGap(221, 221, 221))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(363, 363, 363))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel9)
                .addGap(28, 28, 28)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(txtNoStruk, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(txtTanggal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtJumlahBuku, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(txtHarga, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(txtIdBuku, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(txtJudulBuku, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnInput)
                            .addComponent(btnBatal)))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel8)
                .addGap(1, 1, 1)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtTotalHarga, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(60, 60, 60))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );

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

    private void btnInputActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        try {
                String no_struk= txtNoStruk.getText();
                String tanggal = txtTanggal.getText();
                String id_buku = txtIdBuku.getText();
                String jumlah_buku = txtJumlahBuku.getText();
                
                
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tokobuku","root","713");
Statement stmt;
                stmt = conn.createStatement();
                total_harga= Integer.parseInt(txtHarga.getText()) * Integer.parseInt(jumlah_buku);
                stmt.executeUpdate("insert into struk_pembayaran values('"+no_struk+"','"+tanggal+"','"+total_harga+"','"+jumlah_buku+"','"+id_buku+"')");
                JOptionPane.showMessageDialog(null, "Data berhasil di input");
                txtJumlahBuku.setText("");
                txtJudulBuku.setText("");
                txtHarga.setText("");
                txtIdBuku.setText("");
                hapusdatatabel();
                tampil2();
                 
                conn.close();
                
} catch (Exception exc) {
System.out.println("JDBC Driver,tidak ditemukan atau rusak :: " + exc);  
}
    }                                        

    private void btnBatalActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        try {
                String no_struk = txtNoStruk.getText();
               
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tokobuku","root","713");
Statement stmt;
                stmt = conn.createStatement();
                stmt.executeUpdate("delete from struk_pembayaran where no_struk like '"+no_struk+"'");
                JOptionPane.showMessageDialog(null, "Data berhasil di hapus");
                hapusdatatabel();
                tampil2();
                txtNoStruk.setText("");
                txtTanggal.setText("");
                txtTotalHarga.setText("");
                txtJumlahBuku.setText("");
                txtIdBuku.setText("");
               
                
                conn.close();
                
} catch (Exception exc) {
System.out.println("JDBC Driver,tidak ditemukan atau rusak :: " + exc);  
}
    }                                        

    private void txtTotalHargaActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
        try {
                String no_struk = txtNoStruk.getText(); 
                Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tokobuku","root","713");
Statement stmt;
                stmt = conn.createStatement();
        
                ResultSet rs= stmt.executeQuery("select sum(total_harga) from struk_pembayaran where no_struk = '"+no_struk+"'");
                if(rs.next())
                {
                    String total= rs.getString("sum(total_harga)");
                    txtTotalHarga.setText(total);
                
                 }
               
          }
        catch (Exception exc) {
System.out.println("JDBC Driver,tidak ditemukan atau rusak :: " + exc);  
}
    }                                             

    /**
     * @param args the command line arguments
     */
    public void hapusdatatabel(){
        int row= def1.getRowCount();
        
        for (int i = 0; i<row; i++)
        {
            def1.removeRow(0);
            
        }
    }
    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(Struk_Pembayaran.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Struk_Pembayaran.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Struk_Pembayaran.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Struk_Pembayaran.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 Struk_Pembayaran().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JButton btnBatal;
    private javax.swing.JButton btnInput;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable tblBuku;
    private javax.swing.JTable tblStruk_Pembayaran;
    private javax.swing.JTextField txtHarga;
    private javax.swing.JTextField txtIdBuku;
    private javax.swing.JTextField txtJudulBuku;
    private javax.swing.JTextField txtJumlahBuku;
    private javax.swing.JTextField txtNoStruk;
    private javax.swing.JTextField txtTanggal;
    private javax.swing.JTextField txtTotalHarga;
    // End of variables declaration                   
}




1 komentar:

  1. Slots & Live Dealer Casinos - MapYRO
    Get the best of 보령 출장안마 the casino experience at MapYRO. 파주 출장샵 Browse 군산 출장샵 Live Casino Games, Slots, Table 부천 출장마사지 Games, Poker and Bingo 동해 출장마사지 at MapYRO.

    BalasHapus