Sourcode Aplikasi Toko Sederhana menggunakan Pemrograman Java

Assallamuallaikum Warrohmatulahhi Wabarrokatu

MEMBUAT APLIKASI TOKO MENGGUNAKAN JAVA NETBEANS DAN MYSQL

Perkenalkan dulu nama saya adalah fery febrianto lahir di MADIUN, itu saja informasi dari saya pppfff.....

Oke sekarang kita masuk ke media pembahasan tentang aplikasi java NetBeans dan Mysql. Kedua Aplikasi ini sangatlah berhubungan dalam pembuatan aplikasi dan data base untuk penyimpanannya.
Maka dari itu jika anda ingin membuat aplikasi harus sudah terinstall aplikasi NeatBeans dan XAMPP, itu merupakan hal yang wajib.
Nah sebelum kita mengetik codingan atau lebih gampangnya mengcopy,,hahaha,.anda harus membuat data basenya dulu di php myadmin..

Buat seperti gambar dibawah ini :
database toko 
Ingat Beri judul DbTokoABC, jangan sampai salah.
jika anda sudah membuat data basenya maka anda harus mengetik atau mengcopy codingan di bawah ini dan paste ke notepad atau notepad++.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Locale;
public class AplikasiToko extends JFrame{
/*Untuk koneksi ke MySQL*/
final static String StringDriver="com.mysql.jdbc.Driver";
final static String StringConnection="jdbc:mysql://localhost:3306/DbTokoABC?user=root&password=root";
/*Untuk koneksi ke SQLServer*/
//final static String StringDriver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
//final static String StringConnection="jdbc:sqlserver://localhost:1433;databaseName=DbTokoABC;integratedSecurity=true";
private JDesktopPane frmMDI;
private JInternalFrame frmBarang;
private JInternalFrame frmCustomer;
private JInternalFrame frmPenjualan;
private JFrame frmDaftarBarang;
private JFrame frmDaftarCustomer;
private JFrame frmJualDaftarBarang;
private JFrame frmJualDaftarCustomer;
private JPanel pnlBarang;
private JPanel pnlCustomer;
private JPanel pnlPenjualan;
private JMenuBar MenuBar = new JMenuBar();
private JMenu MenuMaster = new JMenu("Master Data");
private JMenuItem MenuBarang = new JMenuItem("Barang"),
MenuCustomer = new JMenuItem("Customer");
private JMenu MenuTransaksi = new JMenu("Transaksi");
private JMenuItem MenuPenjualan = new JMenuItem("Penjualan");
private JMenuItem MenuExit = new JMenuItem("Exit");
/*Mendefinisikan komponen-komponen untuk Form DaftarBarang*/
private JPanel pnlDaftarBarang;
static String JudulKolomTabelDaftarBarang[] = {"Kode","Nama Barang", "Satuan"};
static DefaultTableModel ModelTabelDaftarBarang = new DefaultTableModel(null,JudulKolomTabelDaftarBarang);
static JTable TabelDaftarBarang = new JTable(){
    public boolean isCellEditable(int rowIndex, int colIndex) {
        return false;
 //Disable Editing
    }
}; JScrollPane ScrollBarDaftarBarang = new JScrollPane();
private static JButton TblDaftarBarangPilih = new JButton("Pilih");
private static JButton TblDaftarBarangBatal = new JButton("Batal");
/*Mendefinisikan komponen-komponen untuk Form DaftarCustomer*/
private JPanel pnlDaftarCustomer;
static String JudulKolomTabelDaftarCustomer[] = {"Kode","Nama Customer","Alamat Customer"};
static DefaultTableModel ModelTabelDaftarCustomer = new DefaultTableModel(null,JudulKolomTabelDaftarCustomer);
static JTable TabelDaftarCustomer = new JTable(){
    public boolean isCellEditable(int rowIndex, int colIndex) { return false;
 //Disable Editing
    }
}; JScrollPane ScrollBarDaftarCustomer = new JScrollPane();
private static JButton TblDaftarCustomerPilih = new JButton("Pilih");
private static JButton TblDaftarCustomerBatal = new JButton("Batal");
/*Mendefinisikan komponen-komponen untuk Form JualDaftarBarang*/
private JPanel pnlJualDaftarBarang; static String JudulKolomTabelJualDaftarBarang[] = {"Kode","Nama Barang","Satuan"};
static DefaultTableModel ModelTabelJualDaftarBarang = new DefaultTableModel(null,JudulKolomTabelJualDaftarBarang);
static JTable TabelJualDaftarBarang = new JTable(){
    public boolean isCellEditable(int rowIndex, int colIndex) {
        return false;
 //Disable Editing

}
};
JScrollPane ScrollBarJualDaftarBarang = new JScrollPane();
private static JButton TblJualDaftarBarangPilih = new JButton("Pilih");
private static JButton TblJualDaftarBarangBatal = new JButton("Batal");
/*Mendefinisikan komponen-komponen untuk Form DaftarCustomer*/ private JPanel pnlJualDaftarCustomer;
static String JudulKolomTabelJualDaftarCustomer[] = {"Kode","Nama Customer","Alamat Customer"};
static DefaultTableModel ModelTabelJualDaftarCustomer = new DefaultTableModel(null,JudulKolomTabelJualDaftarCustomer);
static JTable TabelJualDaftarCustomer = new JTable(){
    public boolean isCellEditable(int rowIndex, int colIndex) {
        return false;
//Disable Editing
    }
};
JScrollPane ScrollBarJualDaftarCustomer = new JScrollPane();
private static JButton TblJualDaftarCustomerPilih = new JButton("Pilih");
private static JButton TblJualDaftarCustomerBatal = new JButton("Batal");
/*Komponen untuk Form Barang*/
private static JLabel LblKodeBarang = new JLabel("Kode Barang");
private static JTextField TxtKodeBarang = new JTextField();
private static JLabel LblNamaBarang = new JLabel("Nama Barang");
private static JTextField TxtNamaBarang = new JTextField();
private static JLabel LblSatuanBarang = new JLabel("Satuan");
private static JTextField TxtSatuanBarang = new JTextField();
private static JLabel LblHargaBarang = new JLabel("Harga Barang");
private static JTextField TxtHargaBarang = new JTextField();
private static JLabel LblStockBarang = new JLabel("Stock Barang");
private static JTextField TxtStockBarang = new JTextField();
private static JButton TblBarangDelete = new JButton("Delete");
private static JButton TblBarangSave = new JButton("Save");
private static JButton TblBarangCancel = new JButton("Cancel");
/*Komponen untuk Form Customer*/
private static JLabel LblKodeCustomer = new JLabel("Kode Customer");
private static JTextField TxtKodeCustomer = new JTextField();
private static JLabel LblNamaCustomer = new JLabel("Nama Customer");
private static JTextField TxtNamaCustomer = new JTextField();
private static JLabel LblAlamatCustomer = new JLabel("Alamat Customer" );
private static JTextField TxtAlamatCustomer = new JTextField();
private static JLabel LblNoTeleponCustomer = new JLabel("No. Telepon" );
private static JTextField TxtNoTeleponCustomer = new JTextField();
private static JLabel LblEmailCustomer = new JLabel("Email");
private static JTextField TxtEmailCustomer = new JTextField();
private static JButton TblCustomerDelete = new JButton("Delete");
private static JButton TblCustomerSave = new JButton("Save");
private static JButton TblCustomerCancel = new JButton("Cancel");
Dimension dimensi = Toolkit.getDefaultToolkit().getScreenSize();
/*Mendefinisikan komponen-komponen untuk Form Penjualan*/
private JPanel pnlCustomerJual;
private JPanel pnlDetilPenjualan;
private static JLabel LblNoNotaJual = new JLabel("No. Nota");
private static JTextField TxtNoNotaJual = new JTextField();
private static JLabel LblKodeCustomerJual = new JLabel("Kode Customer");
private static JTextField TxtKodeCustomerJual = new JTextField();
private static JLabel LblNamaCustomerJual = new JLabel("Nama Customer");
private static JTextField TxtNamaCustomerJual = new JTextField();
private static JLabel LblKodeBarangJual = new JLabel("Kode Barang");
private static JTextField TxtKodeBarangJual = new JTextField();
private static JLabel LblNamaBarangJual = new JLabel("Nama Barang");
private static JTextField TxtNamaBarangJual = new JTextField();
private static JLabel LblHargaBarangJual = new JLabel("Harga");
private static JTextField TxtHargaBarangJual = new JTextField();
private static JLabel LblJumlahJual = new JLabel("Jumlah");
private static JTextField TxtJumlahJual = new JTextField();
private static JLabel LblSubTotalJual = new JLabel("Sub Total");
private static JTextField TxtSubTotalJual = new JTextField();
private static JLabel LblTotalJual = new JLabel("Total");
private static JTextField TxtTotalJual = new JTextField();
private static JLabel LblBayarJual = new JLabel("Pembayaran");
private static JTextField TxtBayarJual = new JTextField();
private static JLabel LblKembaliJual = new JLabel("Kembalian");
private static JTextField TxtKembaliJual = new JTextField();
static String JudulKolomTabelPenjualan[] = {"No.","Kode","Nama Barang", "Harga","Jumlah","Total"};
static DefaultTableModel ModelTabelPenjualan = new DefaultTableModel(null,JudulKolomTabelPenjualan);
static JTable TabelPenjualan = new JTable(){ public boolean isCellEditable(int rowIndex, int colIndex) {
    return false; //Disable Editing
}
}; JScrollPane ScrollBarPenjualan = new JScrollPane();
private static JButton TblJualBarangDaftar = new JButton("Daftar");
private static JButton TblJualCustomerDaftar = new JButton("Daftar");
private static JButton TblPenjualanNoBaru = new JButton("No. Baru");

private static JButton TblPenjualanTambah = new JButton("Tambah");
private static JButton TblPenjualanSave = new JButton("Save");
private static JButton TblPenjualanCancel = new JButton("Cancel");
/*Menu Popup Penjualan*/
private JPopupMenu MenuPopupPenjualan = new JPopupMenu();
private JMenuItem MenuPenjualanDelete = new JMenuItem("Delete");
AplikasiToko(){
super("Aplikasi Toko");
setSize((int)(0.7*dimensi.width),(int)(0.7*dimensi.height));
setLocation(dimensi.width/2-getWidth()/2,dimensi.height/2-getHeight()/2);
setDefaultCloseOperation(EXIT_ON_CLOSE);
frmMDI = new JDesktopPane ();
frmMDI.setLayout(null);
//insets = frmMDI.getInsets();
this.add(frmMDI);
/*Menambahkan menu MDI*/
MenuMaster.add(MenuBarang);
MenuMaster.add(MenuCustomer);
MenuBar.add(MenuMaster);
MenuTransaksi.add(MenuPenjualan);
MenuBar.add(MenuTransaksi);
MenuBar.add(MenuExit);
/*Mendeteksi event pada menu*/
MenuBarang.addActionListener(new MenuHandler());
MenuCustomer.addActionListener(new MenuHandler());
MenuPenjualan.addActionListener(new MenuHandler());
MenuExit.addActionListener(new MenuHandler());
/*Mendeteksi event pada Button di Form Barang*/
TblBarangDelete.addActionListener(new TombolBarangHandler());
TblBarangSave.addActionListener(new TombolBarangHandler());
TblBarangCancel.addActionListener(new TombolBarangHandler());
/*Mendeteksi event pada Button di Form Customer*/
TblCustomerDelete.addActionListener(new TombolCustomerHandler());
TblCustomerSave.addActionListener(new TombolCustomerHandler());
TblCustomerCancel.addActionListener(new TombolCustomerHandler());
/*Mendeteksi event pada Button di Form JualDaftarBarang*/
TblJualDaftarBarangPilih.addActionListener(new TombolJualDaftarBarangHandler());
TblJualDaftarBarangBatal.addActionListener(new TombolJualDaftarBarangHandler());
/*Mendeteksi event pada Button di Form JualDaftarCustomer*/
TblJualDaftarCustomerPilih.addActionListener(new TombolJualDaftarCustomerHandler());
TblJualDaftarCustomerBatal.addActionListener(new TombolJualDaftarCustomerHandler());
/*Mendeteksi event pada Button di Form Penjualan*/
TblJualBarangDaftar.addActionListener(new TombolPenjualanHandler());
TblJualCustomerDaftar.addActionListener(new TombolPenjualanHandler());
TblPenjualanNoBaru.addActionListener(new TombolPenjualanHandler());
TblPenjualanTambah.addActionListener(new TombolPenjualanHandler());
TblPenjualanSave.addActionListener(new TombolPenjualanHandler());
TblPenjualanCancel.addActionListener(new TombolPenjualanHandler());
/*Mendeteksi event pada Button di Form JualDaftarBarang*/
TblJualDaftarBarangPilih.addActionListener(new TombolJualDaftarBarangHandler());
TblJualDaftarBarangBatal.addActionListener(new TombolJualDaftarBarangHandler());
/*Mendeteksi event pada Button di Form JualDaftarCustomer*/
TblJualDaftarCustomerPilih.addActionListener(new TombolJualDaftarCustomerHandler());
TblJualDaftarCustomerBatal.addActionListener(new TombolJualDaftarCustomerHandler());
/*Mendeteksi event pada TxtKodeBarang di Form Barang*/
TxtKodeBarang.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
if (keyCode==KeyEvent.VK_ENTER) {
/*Mulai mencari data barang*/
Boolean JDBC_Err=false;
Connection cn = null;
try {
cn = DriverManager.getConnection(StringConnection);
} catch (Exception ex) {
JDBC_Err=true;
JOptionPane.showMessageDialog(null,"Koneksi ke database DbTokoABC gagal\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
}
if (!JDBC_Err){
try {
cn = DriverManager.getConnection(StringConnection);
String SQLStatemen = "Select * from TbBarang where KodeBarang='"+TxtKodeBarang.getText()+"'";
Statement sta = cn.createStatement();
ResultSet rset = sta.executeQuery(SQLStatemen);
rset.first();
if (rset.getRow()>0){
TxtNamaBarang.setText(rset.getString("NamaBarang"));
TxtSatuanBarang.setText(rset.getString("SatuanBarang"));
TxtHargaBarang.setText(rset.getString("HargaBarang"));
TxtStockBarang.setText(rset.getString("StockBarang"));
sta.close();
rset.close();
} else {
sta.close();
rset.close();
ClearFormBarang();
JOptionPane.showMessageDialog(null,"Kode barang tidak ada");
}
} catch (Exception ex){
JOptionPane.showMessageDialog(null,"Tidak dapat membuka tabel TbBarang\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
}
}
/*selesai mencari data barang*/
}
}
});
/*Mendeteksi event pada TxtKodeCustomer di Form Customer*/
TxtKodeCustomer.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
if (keyCode==KeyEvent.VK_ENTER) {
/*Mulai mencari data Customer*/
Boolean JDBC_Err=false;
Connection cn = null;
try {
cn = DriverManager.getConnection(StringConnection);
} catch (Exception ex) {
JDBC_Err=true;
JOptionPane.showMessageDialog(null,"Koneksi ke database DbTokoABC gagal\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
}
if (!JDBC_Err){
try {
cn = DriverManager.getConnection(StringConnection);
String SQLStatemen = "Select * from TbCustomer where KodeCustomer='"+TxtKodeCustomer.getText()+"'";
Statement sta = cn.createStatement();
ResultSet rset = sta.executeQuery(SQLStatemen);
rset.first();
if (rset.getRow()>0){
TxtNamaCustomer.setText(rset.getString("NamaCustomer"));
TxtAlamatCustomer.setText(rset.getString("AlamatCustomer"));
TxtNoTeleponCustomer.setText(rset.getString("NoTelepon"));
TxtEmailCustomer.setText(rset.getString("Email"));
sta.close();
rset.close();
} else {
sta.close();
rset.close();
ClearFormCustomer();
JOptionPane.showMessageDialog(null,"Kode customer tidak ada");
}
} catch (Exception ex){
JOptionPane.showMessageDialog(null,"Tidak dapat membuka tabel TbCustomer\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
}
}
/*selesai mencari data customer*/
}
}
});
TxtNoNotaJual.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { int keyCode = e.getKeyCode();
if (keyCode==KeyEvent.VK_ENTER) {
    /*Mulai mencari data barang*/
    Boolean JDBC_Err=false;
    Connection cn = null;
    try {
        cn = DriverManager.getConnection(StringConnection);
    } catch (Exception ex) {
        JDBC_Err=true;
        JOptionPane.showMessageDialog(null,"Koneksi ke database DbTokoABC gagal\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
    } if (!JDBC_Err){
        try {
            cn = DriverManager.getConnection(StringConnection);
            String SQLStatemen = "Select TbDetilPenjualan.NoNota, TbPenjualan.KodeCustomer,TbCustomer.NamaCustomer," +"TbDetilPenjualan.KodeBarang,TbBarang.NamaBarang, TbDetilPenjualan.Harga, TbDetilPenjualan.Qty," +"(TbDetilPenjualan.Harga*TbDetilPenjualan.Qty) as Subtotal from TbDetilPenjualan inner join " +"TbPenjualan on TbDetilPenjualan.NoNota=TbPenjualan.NoNota inner join TbCustomer on "

+"TbPenjualan.KodeCustomer=TbCustomer.KodeCustomer inner join TbBarang on " +"TbDetilPenjualan.KodeBarang=TbBarang.KodeBarang where TbDetilPenjualan.NoNota='" +TxtNoNotaJual.getText()+"'";
            Statement sta = cn.createStatement();
            ResultSet rset = sta.executeQuery(SQLStatemen);
            rset.next();
            if (rset.getRow()>0){
                TxtKodeCustomerJual.setText(rset.getString("KodeCustomer"));
                TxtNamaCustomerJual.setText(rset.getString("NamaCustomer"));
                do {
                    ModelTabelPenjualan.insertRow(ModelTabelPenjualan.getRowCount(),new Object[]{
                        ModelTabelPenjualan.getRowCount()+1,rset.getString("KodeBarang"),rset.getString("NamaBarang"),rset.getString("Harga"),rset.getString("Qty"),rset.getString("SubTotal")
                    });
                } while (rset.next());
                sta.close();
                rset.close();
                int Total=0,Bayar=0,SubTtl=0;
                int i;
                for (i=0;i<TabelPenjualan.getRowCount();i++){
                    SubTtl=0;
                    try {
                        SubTtl=Integer.parseInt((String)TabelPenjualan.getModel().getValueAt(i,5));
                    } catch (Exception ex){
                    } Total=Total+SubTtl;
                } TxtTotalJual.setText(Integer.toString(Total));
                Bayar=0;
                try {
                    Bayar=Integer.parseInt(TxtBayarJual.getText());
                } catch (Exception ex){
                } TxtKembaliJual.setText(Integer.toString(Bayar-Total));
            } else {
                sta.close();
                rset.close();
                ClearFormPenjualan();
                JOptionPane.showMessageDialog(null,"No. Nota belum ada");
            }
        } catch (Exception ex){
            JOptionPane.showMessageDialog(null,"Tidak dapat membuka tabel TbPenjualan\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
        }
    } try {

TxtSubTotalJual.setText(Integer.toString(Integer.parseInt(TxtHargaBarangJual.getText())*Integer.parseInt(TxtJumlahJual.getText())));
    } catch (Exception ex){
        TxtSubTotalJual.setText("0");
    } /*selesai mencari data barang*/
}
}
});
/*Mendeteksi event pada TxtKodeBarangJual di Form Penjualan*/
TxtKodeBarangJual.addKeyListener(new KeyAdapter() {
    public void keyPressed(KeyEvent e) {
        int keyCode = e.getKeyCode();
        if (keyCode==KeyEvent.VK_ENTER) {
            /*Mulai mencari data barang*/
            Boolean JDBC_Err=false;
            Connection cn = null;
            try { cn = DriverManager.getConnection(StringConnection);
            } catch (Exception ex) { JDBC_Err=true;
            JOptionPane.showMessageDialog(null,"Koneksi ke database DbTokoABC gagal\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
            } if (!JDBC_Err){
                try {
                    cn = DriverManager.getConnection(StringConnection);
                    String SQLStatemen = "Select * from TbBarang where KodeBarang='"+TxtKodeBarangJual.getText()+"'";
                    Statement sta = cn.createStatement();
                    ResultSet rset = sta.executeQuery(SQLStatemen);
                    rset.next();
                    if (rset.getRow()>0){
                        TxtNamaBarangJual.setText(rset.getString("NamaBarang"));
                        TxtHargaBarangJual.setText(rset.getString("HargaBarang"));
                        sta.close();
                        rset.close();
                    } else {
                        sta.close();
                        rset.close();
                        TxtNamaBarangJual.setText("");
                        TxtHargaBarangJual.setText("");
                        JOptionPane.showMessageDialog(null,"Kode barang tidak ada");
                    }
                } catch (Exception ex){
                    JOptionPane.showMessageDialog(null,"Tidak dapat membuka tabel TbBarang\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
                }
            } try {
                TxtSubTotalJual.setText(Integer.toString(Integer.parseInt(TxtHargaBarangJual.getText())*Integer.parseInt(TxtJumlahJual.getText())));
            } catch (Exception ex){

TxtSubTotalJual.setText("0");
            } /*selesai mencari data barang*/
        }
    }
});
/*Mendeteksi event pada TxtKodeCustomerJual di Form Penjualan*/
TxtKodeCustomerJual.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { int keyCode = e.getKeyCode();
if (keyCode==KeyEvent.VK_ENTER) {
    /*Mulai mencari data Customer*/
    Boolean JDBC_Err=false;
    Connection cn = null;
    try { cn = DriverManager.getConnection(StringConnection);
    } catch (Exception ex) {
        JDBC_Err=true;
        JOptionPane.showMessageDialog(null,"Koneksi ke database DbTokoABC gagal\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
    } if (!JDBC_Err){
        try {
            cn = DriverManager.getConnection(StringConnection);
            String SQLStatemen = "Select * from TbCustomer where KodeCustomer='"+TxtKodeCustomerJual.getText()+"'";
            Statement sta = cn.createStatement();
            ResultSet rset = sta.executeQuery(SQLStatemen);
            rset.next();
            if (rset.getRow()>0){
                TxtNamaCustomerJual.setText(rset.getString("NamaCustomer"));
                sta.close();
                rset.close();
            } else {
                sta.close();
                rset.close();
                TxtNamaCustomerJual.setText("");
                JOptionPane.showMessageDialog(null,"Kode customer tidak ada");
            }
        } catch (Exception ex){
            JOptionPane.showMessageDialog(null,"Tidak dapat membuka tabel TbCustomer\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
        }
    }
    /*selesai mencari data customer*/
}
}
});
/*Mendeteksi event pada TxtJumlahJual di Form Penjualan*/
TxtJumlahJual.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent keyEvent) {
    try {

TxtSubTotalJual.setText(Integer.toString(Integer.parseInt(TxtHargaBarangJual.getText())*Integer.parseInt(TxtJumlahJual.getText())));
    } catch (Exception ex){
        TxtSubTotalJual.setText("0");
    }
}
});
/*Mendeteksi event pada TxtPembayaranJual di Form Penjualan*/
TxtBayarJual.addKeyListener(new KeyAdapter() {
    public void keyReleased(KeyEvent keyEvent) {
        int Total=0;
        try {
            Total=Integer.parseInt(TxtTotalJual.getText());
        } catch (Exception ex){
            TxtKembaliJual.setText("0");
        } try {
            TxtKembaliJual.setText(Integer.toString(Integer.parseInt(TxtBayarJual.getText())-Total));
        } catch (Exception ex){
            TxtKembaliJual.setText("0");
        }
    }
});
setContentPane(frmMDI);
frmBarang = new JInternalFrame();
frmBarang.setTitle("Master Data Barang");
frmCustomer = new JInternalFrame("Master Data Customer");
frmPenjualan = new JInternalFrame("Transaksi Penjualan");
/*Pengaturan tampilan Form Barang*/
pnlBarang = new JPanel ();
LblKodeBarang.setBounds(30,20,160,20);
pnlBarang.add(LblKodeBarang);
TxtKodeBarang.setBounds(120,20,100,20);
pnlBarang.add(TxtKodeBarang);
LblNamaBarang.setBounds(30,45,160,20);
pnlBarang.add(LblNamaBarang);
TxtNamaBarang.setBounds(120,45,200,20);
pnlBarang.add(TxtNamaBarang);
LblSatuanBarang.setBounds(30,70,160,20);
pnlBarang.add(LblSatuanBarang);
TxtSatuanBarang.setBounds(120,70,100,20);
pnlBarang.add(TxtSatuanBarang);
LblHargaBarang.setBounds(30,95,160,20);
pnlBarang.add(LblHargaBarang);
TxtHargaBarang.setBounds(120,95,100,20);
pnlBarang.add(TxtHargaBarang);
LblStockBarang.setBounds(30,120,160,20);
pnlBarang.add(LblStockBarang);
TxtStockBarang.setBounds(120,120,100,20);
pnlBarang.add(TxtStockBarang);
/*Menampilkan tombol di form Barang*/
TblBarangDelete.setBounds(50,180,80,30);
pnlBarang.add(TblBarangDelete);
TblBarangSave.setBounds(140,180,80,30);
pnlBarang.add(TblBarangSave);
TblBarangCancel.setBounds(230,180,80,30);
pnlBarang.add(TblBarangCancel);
pnlBarang.setLayout(null);
frmBarang.add(pnlBarang);
/*Pengaturan tampilan Form Customer*/
pnlCustomer = new JPanel ();
LblKodeCustomer.setBounds(30,20,160,20);
pnlCustomer.add(LblKodeCustomer);
TxtKodeCustomer.setBounds(135,20,100,20);
pnlCustomer.add(TxtKodeCustomer);
LblNamaCustomer.setBounds(30,45,160,20);
pnlCustomer.add(LblNamaCustomer);
TxtNamaCustomer.setBounds(135,45,200,20);
pnlCustomer.add(TxtNamaCustomer);
LblAlamatCustomer.setBounds(30,70,160,20);
pnlCustomer.add(LblAlamatCustomer);
TxtAlamatCustomer.setBounds(135,70,320,20);
pnlCustomer.add(TxtAlamatCustomer);
LblNoTeleponCustomer.setBounds(30,95,160,20);
pnlCustomer.add(LblNoTeleponCustomer);
TxtNoTeleponCustomer.setBounds(135,95,200,20);
pnlCustomer.add(TxtNoTeleponCustomer);
LblEmailCustomer.setBounds(30,120,160,20);
pnlCustomer.add(LblEmailCustomer);
TxtEmailCustomer.setBounds(135,120,160,20);
pnlCustomer.add(TxtEmailCustomer);
/*Menampilkan tombol di form Customer*/
TblCustomerDelete.setBounds(80,180,80,30);
pnlCustomer.add(TblCustomerDelete);
TblCustomerSave.setBounds(170,180,80,30);
pnlCustomer.add(TblCustomerSave);
TblCustomerCancel.setBounds(260,180,80,30);
pnlCustomer.add(TblCustomerCancel);
pnlCustomer.setLayout(null);
frmCustomer.add(pnlCustomer);
frmMDI.add(frmBarang);
frmMDI.add(frmCustomer);
frmBarang.setBounds(10,10,367,270);
frmCustomer.setBounds(30,30,500,270);
setJMenuBar(MenuBar);
setVisible(true);
/*Pengaturan tampilan Form Penjualan*/
pnlPenjualan = new JPanel();
LblNoNotaJual.setBounds(30,10,50,20);
pnlPenjualan.add(LblNoNotaJual);
TxtNoNotaJual.setBounds(80,10,100,20);
pnlPenjualan.add(TxtNoNotaJual);
TblPenjualanNoBaru.setBounds(190,7,85,25);
pnlPenjualan.add(TblPenjualanNoBaru);
pnlCustomerJual = new JPanel();
pnlCustomerJual.setBorder(BorderFactory.createTitledBorder("Customer"));
pnlCustomerJual.setBounds(20,35,350,80);
LblKodeCustomerJual.setBounds(10,20,95,20);
pnlCustomerJual.add(LblKodeCustomerJual);
TxtKodeCustomerJual.setBounds(105,20,100,20);
pnlCustomerJual.add(TxtKodeCustomerJual);
LblNamaCustomerJual.setBounds(10,45,95,20);
pnlCustomerJual.add(LblNamaCustomerJual);
TxtNamaCustomerJual.setBounds(105,45,200,20);
pnlCustomerJual.add(TxtNamaCustomerJual);
TxtNamaCustomerJual.setEditable(false);
TblJualCustomerDaftar.setBounds(210,16,70,25);
pnlCustomerJual.add(TblJualCustomerDaftar);
pnlCustomerJual.setLayout(null);
pnlPenjualan.add(pnlCustomerJual);
pnlDetilPenjualan = new JPanel();
pnlDetilPenjualan.setBorder(BorderFactory.createTitledBorder("Detil Penjualan"));
pnlDetilPenjualan.setBounds(20,125,630,230);

LblKodeBarangJual.setBounds(10,20,90,20);
pnlDetilPenjualan.add(LblKodeBarangJual);
TxtKodeBarangJual.setBounds(90,20,100,20);
pnlDetilPenjualan.add(TxtKodeBarangJual);
LblNamaBarangJual.setBounds(10,45,90,20);
pnlDetilPenjualan.add(LblNamaBarangJual);
TxtNamaBarangJual.setBounds(90,45,200,20);
pnlDetilPenjualan.add(TxtNamaBarangJual);
LblHargaBarangJual.setBounds(300,20,50,20);
pnlDetilPenjualan.add(LblHargaBarangJual);
TxtHargaBarangJual.setBounds(350,20,100,20);
pnlDetilPenjualan.add(TxtHargaBarangJual);
LblJumlahJual.setBounds(300,45,50,20);
pnlDetilPenjualan.add(LblJumlahJual);
TxtJumlahJual.setBounds(350,45,60,20);
pnlDetilPenjualan.add(TxtJumlahJual);
LblSubTotalJual.setBounds(460,20,60,20);
pnlDetilPenjualan.add(LblSubTotalJual);
TxtSubTotalJual.setBounds(520,20,100,20);
pnlDetilPenjualan.add(TxtSubTotalJual);
TblJualBarangDaftar.setBounds(195,16,70,25);
pnlDetilPenjualan.add(TblJualBarangDaftar);
TxtNamaBarangJual.setEditable(false);
TxtHargaBarangJual.setEditable(false);
TxtSubTotalJual.setEditable(false);
TblPenjualanTambah.setBounds(520,45,80,25);
pnlDetilPenjualan.add(TblPenjualanTambah);
/*Menambahkan menu PopUp pada tabel penjualan*/
MenuPopupPenjualan.add(MenuPenjualanDelete);
MenuPenjualanDelete.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
        JMenuItem TblPilih = (JMenuItem)e.getSource();
        if (TblPilih.getText().equals("Delete")) {
            if (TabelPenjualan.getSelectedRow()>=0){
                ModelTabelPenjualan.removeRow(TabelPenjualan.getSelectedRow());
                int i;
                for (i=0;i<TabelPenjualan.getRowCount();i++){
                    TabelPenjualan.setValueAt(i+1,i,0);
                }
            }
        }
    }
});
}


private class MenuHandler implements ActionListener {
public void actionPerformed(ActionEvent e){
JMenuItem M = (JMenuItem)e.getSource();

if (M.getText().equals("Barang")) {
frmBarang.setVisible(true);
} else if (M.getText().equals("Customer")) {
frmCustomer.setVisible(true);
}else if (M.getText().equals("Penjualan")) {
    frmPenjualan.setVisible(true);
}
else if (M.getText().equals("Exit")) {
dispose();
}
}
}
private void ClearFormBarang(){
TxtNamaBarang.setText("");
TxtSatuanBarang.setText("");
TxtHargaBarang.setText("");
TxtStockBarang.setText("");
}
private void ClearFormCustomer(){
TxtNamaCustomer.setText("");
TxtAlamatCustomer.setText("");
TxtNoTeleponCustomer.setText("");
TxtEmailCustomer.setText("");
}
private void ClearFormPenjualan(){
    TxtKodeCustomerJual.setText("");
    TxtNamaCustomerJual.setText("");
    TxtKodeBarangJual.setText("");
    TxtNamaBarangJual.setText("");
    TxtHargaBarangJual.setText("");
    TxtJumlahJual.setText("");
    TxtSubTotalJual.setText("");
    TxtTotalJual.setText("");
    TxtBayarJual.setText("");
    TxtKembaliJual.setText("");
    while (TabelPenjualan.getRowCount()>0){ ModelTabelPenjualan.removeRow(0);
    }
}
private class TombolPenjualanHandler implements ActionListener {
    public void actionPerformed(ActionEvent e){
        JButton TblPilih = (JButton)e.getSource();
        Boolean JDBC_Err = false;
        if (TblPilih==TblJualCustomerDaftar) {
            /*Mulai mencari data Customer*/ Connection cn = null;
            try {
                cn = DriverManager.getConnection(StringConnection);
            } catch (Exception ex) {
                JDBC_Err=true;
                JOptionPane.showMessageDialog(null,"Koneksi ke database DbTokoABC gagal\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
            } if (!JDBC_Err){
                try {
                    cn = DriverManager.getConnection(StringConnection);
                    String SQLStatemen = "Select KodeCustomer,NamaCustomer, AlamatCustomer from TbCustomer order by NamaCustomer";
                    Statement sta = cn.createStatement();
                    ResultSet rset = sta.executeQuery(SQLStatemen);
                    ModelTabelJualDaftarCustomer.setRowCount(0);
                    while (rset.next()){
                        ModelTabelJualDaftarCustomer.insertRow(ModelTabelJualDaftarCustomer.getRowCount(),new Object[]{rset.getString("KodeCustomer"),rset.getString("NamaCustomer"),rset.getString("AlamatCustomer")});
                    }
                    sta.close();
                    rset.close();
                } catch (Exception ex){

JOptionPane.showMessageDialog(null,"Tidak dapat membuka tabel TbCustomer\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
                }
            }
            /*selesai mencari data Customer*/
            frmJualDaftarCustomer.setVisible(true);
        } else if (TblPilih==TblJualBarangDaftar) {
            /*Mulai mencari data barang*/ Connection cn = null;
            try { cn = DriverManager.getConnection(StringConnection);
            } catch (Exception ex) {
                JDBC_Err=true;
                JOptionPane.showMessageDialog(null,"Koneksi ke database DbTokoABC gagal\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
            } if (!JDBC_Err){
                try {
                    cn = DriverManager.getConnection(StringConnection);
                    String SQLStatemen = "Select KodeBarang,NamaBarang,SatuanBarang from TbBarang order by NamaBarang";
                    Statement sta = cn.createStatement();
                    ResultSet rset = sta.executeQuery(SQLStatemen);
                    ModelTabelJualDaftarBarang.setRowCount(0);
                    while (rset.next()){
                        ModelTabelJualDaftarBarang.insertRow(ModelTabelJualDaftarBarang.getRowCount(),new Object[]{
                            rset.getString("KodeBarang"), rset.getString("NamaBarang"),rset.getString("SatuanBarang")});
                    } sta.close();
                    rset.close();
                } catch (Exception ex){
                    JOptionPane.showMessageDialog(null,"Tidak dapat membuka tabel TbBarang\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
                }
            }
            /*selesai mencari data barang*/
            frmJualDaftarBarang.setVisible(true);
        } else if (TblPilih.getText().equals("No. Baru")) {
            /*Mulai membuat no. baru*/
            ClearFormPenjualan();
            Connection cn = null;
            try {
                cn = DriverManager.getConnection(StringConnection);
            } catch (Exception ex) {
                JDBC_Err=true;
                JOptionPane.showMessageDialog(null,"Koneksi ke database DbTokoABC gagal\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
            } if (!JDBC_Err){
                java.util.Date WaktuSekarang;
                SimpleDateFormat FormatWaktu;

String tgl="",bln="",thn="",cari="";
FormatWaktu = new SimpleDateFormat ("HH:mm:ss EEEE, dd-MM-yyyy",Locale.getDefault());
WaktuSekarang = new java.util.Date();
FormatWaktu.applyPattern("dd");
try {
    tgl = FormatWaktu.format(WaktuSekarang);
} catch (NumberFormatException n) {
    tgl = "00";
} FormatWaktu.applyPattern("MM");
try { bln = FormatWaktu.format(WaktuSekarang);
} catch (NumberFormatException n) { bln = "00";
} FormatWaktu.applyPattern("yy");
try {
    thn = FormatWaktu.format(WaktuSekarang);
} catch (NumberFormatException n) {
    thn = "00";
} cari=thn+bln+tgl;
try {
    cn = DriverManager.getConnection(StringConnection);
    String SQLStatemen = "Select * from TbPenjualan where Substring(NoNota,1,6)='" +cari+ "' order by NoNota Desc";
    Statement sta = cn.createStatement();
    ResultSet rset = sta.executeQuery(SQLStatemen);
    rset.next();
    if (rset.getRow()>0){
        String NoBaru= Integer.toString(Integer.parseInt(rset.getString("NoNota").substring(6,10))+1);
        while (NoBaru.length()<4){
            NoBaru="0"+NoBaru;
        } TxtNoNotaJual.setText(cari+NoBaru);
    } else {
        TxtNoNotaJual.setText(cari+"0001");
    } sta.close();
    rset.close();
} catch (Exception ex){ JOptionPane.showMessageDialog(null,"Tidak dapat membuka tabel TbPenjualan\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
}
            }
        /*selesai membuat no. baru*/
        } else if (TblPilih.getText().equals("Tambah")) {
            /*Mulai menambah item penjualan*/
            boolean ada=false;
            int i=0;

while (!ada && (i<TabelPenjualan.getRowCount())){
    if (TxtKodeBarangJual.getText().trim().equals(((String)TabelPenjualan.getModel().getValueAt(i,1)).trim())){
        ada=true;
    } else {
        i++;
    }
} if (ada){
    TabelPenjualan.setValueAt(TxtNamaBarangJual.getText(),i,2);
    TabelPenjualan.setValueAt(TxtHargaBarangJual.getText(),i,3);
    TabelPenjualan.setValueAt(TxtJumlahJual.getText(),i,4);
    TabelPenjualan.setValueAt(TxtSubTotalJual.getText(),i,5);
} else {
    ModelTabelPenjualan.insertRow(ModelTabelPenjualan.getRowCount(),new Object[]{ModelTabelPenjualan.getRowCount()+1,TxtKodeBarangJual.getText(),TxtNamaBarangJual.getText(),TxtHargaBarangJual.getText(),TxtJumlahJual.getText(),TxtSubTotalJual.getText()});
} int Total=0,SubTtl,Bayar;
for (i=0;i<TabelPenjualan.getRowCount();i++){
    SubTtl=0;
    try {
        SubTtl=Integer.parseInt((String)TabelPenjualan.getModel().getValueAt(i,5));
    } catch (Exception ex){
    } Total=Total+SubTtl;
} TxtTotalJual.setText(Integer.toString(Total));
Bayar=0;
try {
    Bayar=Integer.parseInt(TxtBayarJual.getText());
} catch (Exception ex){
} TxtKembaliJual.setText(Integer.toString(Bayar-Total));
        /*Selesai menambah item penjualan*/
        } else if (TblPilih.getText().equals("Save")) {
            /*Mulai menyimpan data Customer*/
            Connection cn = null;
            try {
                cn = DriverManager.getConnection(StringConnection);
            } catch (Exception ex) {
                JDBC_Err=true;
                JOptionPane.showMessageDialog(null,"Koneksi ke database DbTokoABC gagal\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
            } if (!JDBC_Err){
                java.util.Date WaktuSekarang;
                SimpleDateFormat FormatWaktu;
                FormatWaktu = new SimpleDateFormat ("yyyy/MM/dd HH:mm:ss",Locale.getDefault());
                WaktuSekarang = new java.util.Date();

String Tanggal="";
Boolean diSimpan=true;
try { Tanggal = FormatWaktu.format(WaktuSekarang);
} catch (NumberFormatException n) {
    Tanggal = "1900/01/01 01:01:01";
}
try {
    cn = DriverManager.getConnection(StringConnection);
    String SQLStatemen = "Select * from TbPenjualan where NoNota='"+TxtNoNotaJual.getText()+"'";
    Statement sta = cn.createStatement();
    ResultSet rset = sta.executeQuery(SQLStatemen);
    int simpan=0; rset.next(); if (rset.getRow()>0){
        sta.close();
        rset.close();
        Object[] arrOpsi = {"Ya","Tidak"};
        int pilih=JOptionPane.showOptionDialog(null,"No. Nota sudah ada\nApakah data diupdate?","Konfirmasi",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,arrOpsi,arrOpsi[0]);
        if (pilih==0){
            SQLStatemen = "update TbPenjualan set Tanggal='"+Tanggal +"', KodeCustomer='"+TxtKodeCustomerJual.getText()+"', IDUser='"+"B" +"' where NoNota='"+TxtNoNotaJual.getText()+"'";
            sta = cn.createStatement();
            simpan = sta.executeUpdate(SQLStatemen);
            sta.close();
        } else {
            diSimpan=false;
        }
    } else {
        sta.close();
        rset.close();
        SQLStatemen = "insert into TbPenjualan values ('"+TxtNoNotaJual.getText()+"','"+Tanggal+"','"+TxtKodeCustomerJual.getText()+"','"+"B"+"')";
        sta = cn.createStatement();
        simpan = sta.executeUpdate(SQLStatemen);
        sta.close();
    } if (diSimpan){
        if (simpan==1){
            int i;
            for (i=0;i<TabelPenjualan.getRowCount();i++){
                SQLStatemen = "Select * from TbDetilPenjualan where NoNota='"+TxtNoNotaJual.getText()+"' and KodeBarang='"+(String)TabelPenjualan.getModel().getValueAt(i,1)+"'";
                sta = cn.createStatement();
                rset = sta.executeQuery(SQLStatemen);
                rset.next();
                if (rset.getRow()>0){
                    SQLStatemen = "update TbDetilPenjualan set Harga='" + Integer.parseInt((String)TabelPenjualan.getModel().getValueAt(i,3)) + "', Qty='"+ Integer.parseInt((String)TabelPenjualan.getModel().getValueAt(i,4)) + "' where NoNota='"+TxtNoNotaJual.getText()+"' and KodeBarang='"+(String)TabelPenjualan.getModel().getValueAt(i,1)+"'";
                    sta = cn.createStatement();
                    simpan = sta.executeUpdate(SQLStatemen);
                    sta.close();
                } else {
                    SQLStatemen = "insert into TbDetilPenjualan values('"+ TxtNoNotaJual.getText() +"','"+ (String)TabelPenjualan.getModel().getValueAt(i,1) +"','"+ Integer.parseInt((String)TabelPenjualan.getModel().getValueAt(i,3)) +"','"+ Integer.parseInt((String)TabelPenjualan.getModel().getValueAt(i,4))+"')";
                    sta = cn.createStatement();
                    simpan = sta.executeUpdate(SQLStatemen);
                    sta.close();
                }
            } JOptionPane.showMessageDialog(null,"Sudah tersimpan");
        } else {
            JOptionPane.showMessageDialog(null,"Gagal menyimpan data penjualan","Kesalahan",JOptionPane.ERROR_MESSAGE);
        }
    }
} catch (Exception ex){
    JOptionPane.showMessageDialog(null,"Tidak dapat membuka tabel TbPenjualan\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
}
            }
            /*selesai menyimpan data Customer*/
            } else if (TblPilih.getText().equals("Cancel")) {
                frmPenjualan.setVisible(false);
            }
        }
    }
private class TombolBarangHandler implements ActionListener {
public void actionPerformed(ActionEvent e){
JButton TblPilih = (JButton)e.getSource();
Boolean JDBC_Err = false;
if (TblPilih.getText().equals("Delete")) {
/*Mulai menghapus data barang*/
Connection cn = null;
try {
cn = DriverManager.getConnection(StringConnection);
} catch (Exception ex) {
JDBC_Err=true;
JOptionPane.showMessageDialog(null,"Koneksi ke database DbTokoABC gagal\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
}
if (!JDBC_Err){
try {
cn = DriverManager.getConnection(StringConnection);
String SQLStatemen = "Select * from TbBarang where KodeBarang='"+TxtKodeBarang.getText()+"'";
Statement sta = cn.createStatement();
ResultSet rset = sta.executeQuery(SQLStatemen);
rset.first();
if (rset.getRow()>0){
sta.close();
rset.close();
SQLStatemen = "delete from TbBarang where KodeBarang='"+ TxtKodeBarang.getText()+"'";
sta = cn.createStatement();
int simpan = sta.executeUpdate(SQLStatemen);
if (simpan==1){
TxtKodeBarang.setText("");
ClearFormBarang();
JOptionPane.showMessageDialog(null,"Sudah dihapus");
} else {
JOptionPane.showMessageDialog(null,"Gagal menghapus data barang","Kesalahan",JOptionPane.ERROR_MESSAGE);
}
} else {
sta.close();
rset.close();
JOptionPane.showMessageDialog(null,"Kode barang tidak ada");
}
} catch (Exception ex){
JOptionPane.showMessageDialog(null,"Tidak dapat membuka tabel TbBarang\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
}
}
/*Selesai menghapus data barang*/
} else if (TblPilih.getText().equals("Save")) {
/*Mulai menyimpan data barang*/
Connection cn = null;
try {
cn = DriverManager.getConnection(StringConnection);
} catch (Exception ex) {
JDBC_Err=true;
JOptionPane.showMessageDialog(null,"Koneksi ke database DbTokoABC gagal\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
}
if (!JDBC_Err){
try {
cn = DriverManager.getConnection(StringConnection);
String SQLStatemen = "Select * from TbBarang where KodeBarang='"+TxtKodeBarang.getText()+"'";
Statement sta = cn.createStatement();
ResultSet rset = sta.executeQuery(SQLStatemen);
rset.first();
if (rset.getRow()>0){
sta.close();
rset.close();
Object[] arrOpsi = {"Ya","Tidak"};
int pilih=JOptionPane.showOptionDialog(null,"Kode Barang sudah ada\nApakah data diupdate?","Konfirmasi",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,arrOpsi,arrOpsi[0]);
if (pilih==0){
SQLStatemen = "update TbBarang set NamaBarang='"+ TxtNamaBarang.getText()+
"', SatuanBarang='"+TxtSatuanBarang.getText()+
"',HargaBarang='"+TxtHargaBarang.getText()+
"', StockBarang='"+TxtStockBarang.getText()+
"' where KodeBarang='"+TxtKodeBarang.getText()+"'";
sta = cn.createStatement();
int simpan = sta.executeUpdate(SQLStatemen);
if (simpan==1){
TxtKodeBarang.setText("");
ClearFormBarang();
JOptionPane.showMessageDialog(null,"Sudah tersimpan");
} else {
JOptionPane.showMessageDialog(null,"Gagal menyimpan data barang","Kesalahan",JOptionPane.ERROR_MESSAGE);
}
}
} else {
sta.close();
rset.close();
SQLStatemen = "insert into TbBarang values ('"+TxtKodeBarang.getText()+"','"+TxtNamaBarang.getText()+"','"+TxtSatuanBarang.getText()+"','"+TxtHargaBarang.getText()+"','"+TxtStockBarang.getText()+"')";
sta = cn.createStatement();
int simpan = sta.executeUpdate(SQLStatemen);
if (simpan==1){
TxtKodeBarang.setText("");
ClearFormBarang();
JOptionPane.showMessageDialog(null,"Sudah tersimpan");
} else {
JOptionPane.showMessageDialog(null,"Gagal menyimpan data barang","Kesalahan",JOptionPane.ERROR_MESSAGE);
}
}
} catch (Exception ex){
JOptionPane.showMessageDialog(null,"Tidak dapat membuka tabel TbBarang\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
}
}
/*selesai menyimpan data barang*/
} else if (TblPilih.getText().equals("Cancel")) {
frmBarang.setVisible(false);
}
}
}
private class TombolCustomerHandler implements ActionListener {
public void actionPerformed(ActionEvent e){
JButton TblPilih = (JButton)e.getSource();
Boolean JDBC_Err = false;
if (TblPilih.getText().equals("Delete")) {
/*Mulai menghapus data Customer*/
Connection cn = null;
try {
cn = DriverManager.getConnection(StringConnection);
} catch (Exception ex) {
JDBC_Err=true;
JOptionPane.showMessageDialog(null,"Koneksi ke database DbTokoABC gagal\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
}
if (!JDBC_Err){
try {
cn = DriverManager.getConnection(StringConnection);
String SQLStatemen = "Select * from TbCustomer where KodeCustomer='"+TxtKodeCustomer.getText()+"'";
Statement sta = cn.createStatement();
ResultSet rset = sta.executeQuery(SQLStatemen);
rset.first();
if (rset.getRow()>0){
sta.close();
rset.close();
SQLStatemen = "delete from TbCustomer where KodeCustomer='"+TxtKodeCustomer.getText()+"'";
sta = cn.createStatement();
int simpan = sta.executeUpdate(SQLStatemen);
if (simpan==1){
TxtKodeCustomer.setText("");
ClearFormCustomer();
JOptionPane.showMessageDialog(null,"Sudah dihapus");
} else {
JOptionPane.showMessageDialog(null,"Gagal menghapus data customer","Kesalahan",JOptionPane.ERROR_MESSAGE);
}
} else {
sta.close();
rset.close();
JOptionPane.showMessageDialog(null,"Kode customer tidak ada");
}
} catch (Exception ex){
JOptionPane.showMessageDialog(null,"Tidak dapat membuka tabel TbCustomer\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
}
}
/*Selesai menghapus data Customer*/
} else if (TblPilih.getText().equals("Save")) {
/*Mulai menyimpan data Customer*/
Connection cn = null;
try {
cn = DriverManager.getConnection(StringConnection);
} catch (Exception ex) {
JDBC_Err=true;
JOptionPane.showMessageDialog(null,"Koneksi ke database DbTokoABC gagal\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
}
if (!JDBC_Err){
try {
cn = DriverManager.getConnection(StringConnection);
String SQLStatemen = "Select * from TbCustomer where KodeCustomer='"+TxtKodeCustomer.getText()+"'";
Statement sta = cn.createStatement();
ResultSet rset = sta.executeQuery(SQLStatemen);
rset.first();
if (rset.getRow()>0){
sta.close();
rset.close();
Object[] arrOpsi = {"Ya","Tidak"};
int pilih=JOptionPane.showOptionDialog(null,"Kode customer sudah ada\nApakah data diupdate?","Konfirmasi", JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,arrOpsi,arrOpsi[0]);
if (pilih==0){
SQLStatemen = "update TbCustomer set NamaCustomer='"+ TxtNamaCustomer.getText()+
"', AlamatCustomer='"+TxtAlamatCustomer.getText()+
"', NoTelepon='"+TxtNoTeleponCustomer.getText()+
"', Email='"+TxtEmailCustomer.getText()+
"' where KodeCustomer='"+TxtKodeCustomer.getText()+ "'";
sta = cn.createStatement();
int simpan = sta.executeUpdate(SQLStatemen);
if (simpan==1){
TxtKodeCustomer.setText("");
ClearFormCustomer();
JOptionPane.showMessageDialog(null,"Sudah tersimpan");
} else {
JOptionPane.showMessageDialog(null,"Gagal menyimpan data customer","Kesalahan",JOptionPane.ERROR_MESSAGE);
}
}
} else {
sta.close();
rset.close();
SQLStatemen = "insert into TbCustomer values ('"+ TxtKodeCustomer.getText()+"','"+TxtNamaCustomer.getText()+"','"+ TxtAlamatCustomer.getText()+"','"+TxtNoTeleponCustomer.getText()+ "','"+TxtEmailCustomer.getText()+"')";
sta = cn.createStatement();
int simpan = sta.executeUpdate(SQLStatemen);
if (simpan==1){
TxtKodeCustomer.setText("");
ClearFormCustomer();
JOptionPane.showMessageDialog(null,"Sudah tersimpan");
} else {
JOptionPane.showMessageDialog(null,"Gagal menyimpan data customer","Kesalahan",JOptionPane.ERROR_MESSAGE);
}
}
} catch (Exception ex){
JOptionPane.showMessageDialog(null,"Tidak dapat membuka tabel TbCustomer\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
}
}
/*selesai menyimpan data Customer*/
} else if (TblPilih.getText().equals("Cancel")) {
frmCustomer.setVisible(false);
}
}
}
/*class untuk memproses ActionEvent dari tombol di form Daftar Barang di form penjualan*/
private class TombolJualDaftarBarangHandler implements ActionListener {
    public void actionPerformed(ActionEvent e){
        JButton TblPilih = (JButton)e.getSource();
        Boolean JDBC_Err = false;
        if (TblPilih.getText().equals("Pilih")) {
            if (TabelJualDaftarBarang.getSelectedRow()>=0){
                TxtKodeBarangJual.setText((String)TabelJualDaftarBarang.getModel().getValueAt(TabelJualDaftarBarang.getSelectedRow(),0));
                frmJualDaftarBarang.setVisible(false);
                frmJualDaftarBarang.dispose();
                /*Mulai mencari data barang*/
                Connection cn = null;
                try {
                    cn = DriverManager.getConnection(StringConnection);
                } catch (Exception ex) {
                    JDBC_Err=true;
                    JOptionPane.showMessageDialog(null,"Koneksi ke database DbTokoABC gagal\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
                } if (!JDBC_Err){
                    try {
                        cn = DriverManager.getConnection(StringConnection);
                        String SQLStatemen = "Select * from TbBarang where KodeBarang='"+TxtKodeBarangJual.getText()+"'";
                        Statement sta = cn.createStatement();
                        ResultSet rset = sta.executeQuery(SQLStatemen);
                        rset.next();
                        if (rset.getRow()>0){
                            TxtNamaBarangJual.setText(rset.getString("NamaBarang"));
                            TxtHargaBarangJual.setText(rset.getString("HargaBarang"));
                            sta.close();
                            rset.close();
                        } else {
                            sta.close();
                            rset.close();
                            ClearFormBarang();
                            JOptionPane.showMessageDialog(null,"Kode barang tidak ada");
                        }
                    } catch (Exception ex){
                        JOptionPane.showMessageDialog(null,"Tidak dapat membuka tabel TbBarang\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
                    }
                }
                /*selesai mencari data barang*/
                try {

TxtSubTotalJual.setText(Integer.toString(Integer.parseInt(TxtHargaBarangJual.getText())*Integer.parseInt(TxtJumlahJual.getText())));
                } catch (Exception ex){
                    TxtSubTotalJual.setText("0");
                }
            } else {
                JOptionPane.showMessageDialog(null,"Belum ada yang dipilih, klik item di tabel");
            }
        } else if (TblPilih.getText().equals("Batal")) {
            frmJualDaftarBarang.setVisible(false);
            frmJualDaftarBarang.dispose();
        }
    }
}
/*class untuk memproses ActionEvent dari tombol di form Daftar Customer di form penjualan*/
private class TombolJualDaftarCustomerHandler implements ActionListener {
public void actionPerformed(ActionEvent e){
    JButton TblPilih = (JButton)e.getSource();
    Boolean JDBC_Err = false;
    if (TblPilih.getText().equals("Pilih")) {
        if (TabelJualDaftarCustomer.getSelectedRow()>=0){
            TxtKodeCustomerJual.setText((String)TabelJualDaftarCustomer.getModel().getValueAt(TabelJualDaftarCustomer.getSelectedRow(),0));
            frmJualDaftarCustomer.setVisible(false);
            frmJualDaftarCustomer.dispose();
            /*Mulai mencari data Customer*/ Connection cn = null;
            try { cn = DriverManager.getConnection(StringConnection);
            } catch (Exception ex) {
                JDBC_Err=true;
                JOptionPane.showMessageDialog(null,"Koneksi ke database DbTokoABC gagal\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
            } if (!JDBC_Err){
                try {
                    cn = DriverManager.getConnection(StringConnection);
                    String SQLStatemen = "Select * from TbCustomer where KodeCustomer='"+TxtKodeCustomerJual.getText()+"'";
                    Statement sta = cn.createStatement();
                    ResultSet rset = sta.executeQuery(SQLStatemen);
                    rset.next();
                    if (rset.getRow()>0){
                        TxtNamaCustomerJual.setText(rset.getString("NamaCustomer"));
                        sta.close();
                        rset.close();
                    } else {
                        sta.close();
                        rset.close();

ClearFormCustomer();
JOptionPane.showMessageDialog(null,"Kode customer tidak ada");
                    }
                } catch (Exception ex){
                    JOptionPane.showMessageDialog(null,"Tidak dapat membuka tabel TbCustomer\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
                }
            }
        /*selesai mencari data customer*/
        } else {
            JOptionPane.showMessageDialog(null,"Belum ada yang dipilih, klik item di tabel");
        }
    } else if (TblPilih.getText().equals("Batal")) {
        frmJualDaftarCustomer.setVisible(false);
        frmJualDaftarCustomer.dispose();
    }
}
}
public static void main(String args[]){
AplikasiToko frameku = new AplikasiToko();
Boolean JDBC_Err = false;
try{
Class.forName(StringDriver);
} catch (Exception ex){
JDBC_Err=true;
JOptionPane.showMessageDialog(null,"JDBC Driver tidak ditemukan atau rusak\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
}
if (!JDBC_Err){
try {
Connection cn = DriverManager.getConnection(StringConnection);
} catch (Exception ex) {
JOptionPane.showMessageDialog(null,"Koneksi ke database DbTokoABC gagal\n"+ex,"Kesalahan",JOptionPane.ERROR_MESSAGE);
}
}
}
}


Jika anda sudah mengcopy save dengan nama AplikasiTokoABC.java
lalu coba running atau jalankan program AplikasiTokoABC
jika aplikasi berjalan maka akan muncul tampilan seperti di bawah ini:

aplikasi sederhana toko kasir

trimakasih telah membaca dan memahami blogg dari saya
Sekian penjelasan dari saya kalau ada error maupun kesalahan mohon comentar dibawah.
mohon sempatkan comment yang baik dan santun

jika ingin mendownload databasenya silahkan DOWNLOAD DISINI
TERIMAKASIH

Wassallamualaikum Warrohmatulahhi Wabarrokatu