Membuat Program Client Server Menggunakan Java dan MySQL

Untuk membuat program Client Server pada data barang, kita hanya mengubah program data barang yang sudah kita buat pada posting sebelumnya. Berikut langkah-langkahnya:

  1. Langkah pertama, kita harus membuat 3 project baru (MiniMarket-API, MiniMarket-Server, dan MiniMarket-Client).
  2. Tambahkan project MiniMarket-API pada MiniMarket-Server dan MiniMarket-Client.
  3. Tambahkan juga library MySQL JDBC Driver pada MiniMarket-Server.
  4. Pada MiniMarket-API, buat 2 package baru, yaitu: Entitas dan Services.
  5. Pada package Entitas, tambahkan 2 class baru, yaitu: Barang dan Kategori.
  6. Tambahkan script dibawah ini pada class Barang.
  7. /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package Entitas;
    
    import java.io.Serializable;
    
    /**
     *
     * @author AdhityaBEe
     */
    public class Barang implements Serializable {
    
        private String idBrg;
        private String kategori;
        private String namaBrg;
        private int stokBrg;
        private double hrgJual;
    
        public String getIdBrg() {
            return idBrg;
        }
    
        public void setIdBrg(String idBrg) {
            this.idBrg = idBrg;
        }
    
        public String getKategori() {
            return kategori;
        }
    
        public void setKategori(String kategori) {
            this.kategori = kategori;
        }
    
        public String getNamaBrg() {
            return namaBrg;
        }
    
        public void setNamaBrg(String namaBrg) {
            this.namaBrg = namaBrg;
        }
    
        public int getStokBrg() {
            return stokBrg;
        }
    
        public void setStokBrg(int stokBrg) {
            this.stokBrg = stokBrg;
        }
    
        public double getHrgJual() {
            return hrgJual;
        }
    
        public void setHrgJual(double hrgJual) {
            this.hrgJual = hrgJual;
        }
    }
    
  8. Tambahkan script dibawah ini pada class Kategori.
  9. /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package Entitas;
    
    import java.io.Serializable;
    
    /**
     *
     * @author AdhityaBEe
     */
    public class Kategori implements Serializable {
    
        private String kategori;
        private String deskripsi;
    
        public String getKategori() {
            return kategori;
        }
    
        public void setKategori(String kategori) {
            this.kategori = kategori;
        }
    
        public String getDeskripsi() {
            return deskripsi;
        }
    
        public void setDeskripsi(String deskripsi) {
            this.deskripsi = deskripsi;
        }
    }
    
  10. Pada package Services, tambahkan 2 class baru, yaitu: ServicesBarang dan ServicesKategori.
  11. Tambahkan script dibawah ini pada class ServicesBarang.
  12. /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package Services;
    
    import Entitas.Barang;
    import java.rmi.Remote;
    import java.rmi.RemoteException;
    import java.util.List;
    
    /**
     *
     * @author AdhityaBEe
     */
    public interface ServicesBarang extends Remote {
    
        List getBarang() throws RemoteException;
    
        void insert(Barang barang) throws RemoteException;
    
        void update(Barang barang) throws RemoteException;
    
        void delete(Barang barang) throws RemoteException;
    
        void cari(Barang barang) throws RemoteException;
    }
    
  13. Tambahkan script dibawah ini pada class ServicesKategori.
  14. /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package Services;
    
    import Entitas.Kategori;
    import java.rmi.Remote;
    import java.rmi.RemoteException;
    import java.util.List;
    
    /**
     *
     * @author AdhityaBEe
     */
    public interface ServicesKategori extends Remote {
    
        List getKategori() throws RemoteException;
    
        void insert(Kategori kategori) throws RemoteException;
    
        void update(Kategori kategori) throws RemoteException;
    
        void delete(Kategori kategori) throws RemoteException;
    }
    
  15. Pada MiniMarket-Server, buat 3 package baru, yaitu: AksesRMI, Koneksi, dan Server.
  16. Pada package AksesRMI, tambahkan 2 class baru, yaitu: AksesBarang dan AksesKategori.
  17. Tambahkan script dibawah ini pada class AksesBarang.
  18. /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package AksesRMI;
    
    import Entitas.Barang;
    import Koneksi.Koneksi;
    import java.rmi.RemoteException;
    import java.rmi.server.UnicastRemoteObject;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.List;
    
    /**
     *
     * @author AdhityaBEe
     */
    public class AksesBarang extends UnicastRemoteObject implements Services.ServicesBarang {
    
        public AksesBarang() throws RemoteException {
        }
    
        @Override
        public List getBarang() throws RemoteException {
            List listBarang = new ArrayList<>();
            Statement statement = null;
            try {
                statement = Koneksi.getConnection().createStatement();
                ResultSet resultSet = statement.executeQuery("SELECT * FROM barang");
                while (resultSet.next()) {
                    Barang barang = new Barang();
                    barang.setIdBrg(resultSet.getString(1));
                    barang.setKategori(resultSet.getString(2));
                    barang.setNamaBrg(resultSet.getString(3));
                    barang.setStokBrg(Integer.valueOf(resultSet.getString(4)));
                    barang.setHrgJual(Double.valueOf(resultSet.getString(5)));
                    listBarang.add(barang);
                }
                resultSet.close();
                return listBarang;
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return null;
            } finally {
                if (statement != null) {
                    try {
                        statement.close();
                    } catch (Exception e) {
                    }
                }
            }
        }
    
        @Override
        public void insert(Barang barang) throws RemoteException {
            Statement statement = null;
            try {
                statement = Koneksi.getConnection().createStatement();
                statement.executeUpdate("INSERT INTO barang VALUES ('" + barang.getIdBrg() + "','" + barang.getKategori() + "','" + barang.getNamaBrg() + "','0','0')");
            } catch (Exception e) {
                System.out.println(e.getMessage());
            } finally {
                if (statement != null) {
                    try {
                        statement.close();
                    } catch (Exception e) {
                    }
                }
            }
        }
    
        @Override
        public void update(Barang barang) throws RemoteException {
            Statement statement = null;
            try {
                statement = Koneksi.getConnection().createStatement();
                statement.executeUpdate("UPDATE barang SET kategori='" + barang.getKategori() + "',nama_barang='" + barang.getNamaBrg() + "'WHERE id_barang='" + barang.getIdBrg() + "'");
            } catch (Exception e) {
                System.out.println(e.getMessage());
            } finally {
                if (statement != null) {
                    try {
                        statement.close();
                    } catch (Exception e) {
                    }
                }
            }
        }
    
        @Override
        public void delete(Barang barang) throws RemoteException {
            Statement statement = null;
            try {
                statement = Koneksi.getConnection().createStatement();
                statement.executeUpdate("DELETE FROM barang WHERE id_barang='" + barang.getIdBrg() + "'");
            } catch (Exception e) {
                System.out.println(e.getMessage());
            } finally {
                if (statement != null) {
                    try {
                        statement.close();
                    } catch (Exception e) {
                    }
                }
            }
        }
    
        @Override
        public void cari(Barang barang) throws RemoteException {
            Statement statement = null;
            try {
                statement = Koneksi.getConnection().createStatement();
                statement.executeQuery("SELECT id_barang,kategori,nama_barang,stok_barang FROM barang WHERE nama_barang LIKE '%" + barang.getNamaBrg() + "%' GROUP BY id_barang");
            } catch (Exception e) {
                System.out.println(e.getMessage());
            } finally {
                if (statement != null) {
                    try {
                        statement.close();
                    } catch (Exception e) {
                    }
                }
            }
        }
    }
    
  19. Tambahkan script dibawah ini pada class AksesKategori.
  20. /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package AksesRMI;
    
    import Entitas.Kategori;
    import Koneksi.Koneksi;
    import java.rmi.RemoteException;
    import java.rmi.server.UnicastRemoteObject;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.List;
    
    /**
     *
     * @author AdhityaBEe
     */
    public class AksesKategori extends UnicastRemoteObject implements Services.ServicesKategori {
    
        public AksesKategori() throws RemoteException {
        }
    
        @Override
        public List getKategori() throws RemoteException {
            List listKategori = new ArrayList<>();
            Statement statement = null;
            try {
                statement = Koneksi.getConnection().createStatement();
                ResultSet resultSet = statement.executeQuery("SELECT * FROM kategori");
                while (resultSet.next()) {
                    Kategori kategori = new Kategori();
                    kategori.setKategori(resultSet.getString(1));
                    kategori.setDeskripsi(resultSet.getString(2));
                    listKategori.add(kategori);
                }
                resultSet.close();
                return listKategori;
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return null;
            } finally {
                if (statement != null) {
                    try {
                        statement.close();
                    } catch (Exception e) {
                    }
                }
            }
        }
    
        @Override
        public void insert(Kategori kategori) throws RemoteException {
            Statement statement = null;
            try {
                statement = Koneksi.getConnection().createStatement();
                statement.executeUpdate("INSERT INTO kategori VALUES ('" + kategori.getKategori() + "','" + kategori.getDeskripsi() + "')");
            } catch (Exception e) {
                System.out.println(e.getMessage());
            } finally {
                if (statement != null) {
                    try {
                        statement.close();
                    } catch (Exception e) {
                    }
                }
            }
        }
    
        @Override
        public void update(Kategori kategori) throws RemoteException {
            Statement statement = null;
            try {
                statement = Koneksi.getConnection().createStatement();
                statement.executeUpdate("");
            } catch (Exception e) {
                System.out.println(e.getMessage());
            } finally {
                if (statement != null) {
                    try {
                        statement.close();
                    } catch (Exception e) {
                    }
                }
            }
        }
    
        @Override
        public void delete(Kategori kategori) throws RemoteException {
            Statement statement = null;
            try {
                statement = Koneksi.getConnection().createStatement();
                statement.executeUpdate("DELETE FROM kategori WHERE kategori='" + kategori.getKategori() + "'");
            } catch (Exception e) {
                System.out.println(e.getMessage());
            } finally {
                if (statement != null) {
                    try {
                        statement.close();
                    } catch (Exception e) {
                    }
                }
            }
        }
    }
    
  21. Pada package Koneksi, tambahkan class Koneksi.
  22. Tambahkan script dibawah ini pada class Koneksi.
  23. /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package Koneksi;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    
    /**
     *
     * @author AdhityaBEe
     */
    public class Koneksi {
    
        private static Connection connection = null;
    
        public static Connection getConnection() {
            try {
                Class.forName("com.mysql.jdbc.Driver").newInstance();
                connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/minimarket", "root", "");
            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException e) {
                System.out.println(e.getMessage());
            }
            return connection;
        }
        public static void main(String[] args) {
    
        }
    }
    
  24. Pada package Server, tambahkan class Server.
  25. Tambahkan script dibawah ini pada class Server.
  26. /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package Server;
    
    import AksesRMI.AksesBarang;
    import AksesRMI.AksesKategori;
    import AksesRMI.AksesPengadaanBarang;
    import AksesRMI.AksesUser;
    import java.rmi.Remote;
    import java.rmi.RemoteException;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.registry.Registry;
    
    /**
     *
     * @author AdhityaBEe
     */
    public class Server {
    
        public static void main(String[] args) throws RemoteException {
            Registry registry = LocateRegistry.createRegistry(1099);
            AksesBarang aksesBarang = new AksesBarang();
            AksesKategori aksesKategori = new AksesKategori();
            AksesUser aksesUser = new AksesUser();
            AksesPengadaanBarang aksesPengadaanBarang = new AksesPengadaanBarang();
    
            registry.rebind("barang", (Remote) aksesBarang);
            registry.rebind("kategori", (Remote) aksesKategori);
            registry.rebind("user", (Remote) aksesUser);
            registry.rebind("pengadaanBrg", (Remote) aksesPengadaanBarang);
            System.out.println("Server Activated");
        }
    }
    
  27. Edit script pada class DaftarBarang seperti dibawah ini.
  28. /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package MiniMarket;
    
    import Entitas.Barang;
    import Entitas.Kategori;
    import Services.ServicesBarang;
    import Services.ServicesKategori;
    import java.rmi.NotBoundException;
    import java.rmi.RemoteException;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.registry.Registry;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.JOptionPane;
    import javax.swing.table.DefaultTableModel;
    
    /**
     *
     * @author AdhityaBEe
     */
    public class DaftarBarang extends javax.swing.JFrame {
    
        final ServicesBarang servicesBarang;
        final ServicesKategori servicesKategori;
    
        /**
         * Creates new form KategoriBarang
         */
        public DaftarBarang() throws RemoteException, NotBoundException {
            Registry registry = LocateRegistry.getRegistry(1099);
            servicesBarang = (ServicesBarang) registry.lookup("barang");
            servicesKategori = (ServicesKategori) registry.lookup("kategori");
            initComponents();
            select(servicesBarang);
            panggilKategori(servicesKategori);
            this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        }
    
        private void select(ServicesBarang servicesBarang1) throws RemoteException {
            List listBarang = new ArrayList<>();
            String header[] = {"ID Barang", "Kategori", "Nama Barang", "Stok Barang", "Harga Jual"};
            DefaultTableModel defaultTableModel = new DefaultTableModel(null, header);
            tblBarang.setModel(defaultTableModel);
            for (int i = 0; i < tblBarang.getRowCount(); i++) {
                defaultTableModel.removeRow(i);
            }
            listBarang = servicesBarang1.getBarang();
            for (int i = 0; i < listBarang.size(); i++) {
                Object baris[] = {listBarang.get(i).getIdBrg(), listBarang.get(i).getKategori(), listBarang.get(i).getNamaBrg(), listBarang.get(i).getStokBrg(), listBarang.get(i).getHrgJual()};
                defaultTableModel.addRow(baris);
            }
        }
    
        private void insert(ServicesBarang servicesBarang1) throws RemoteException {
            Barang b = new Barang();
            b.setIdBrg(txtIDBarang.getText());
            b.setKategori(cbKategori.getSelectedItem().toString());
            b.setNamaBrg(txtNamaBarang.getText());
            servicesBarang1.insert(b);
        }
    
        private void update(ServicesBarang servicesBarang1) throws RemoteException {
            Barang b = new Barang();
            b.setIdBrg(txtIDBarang.getText());
            b.setKategori(cbKategori.getSelectedItem().toString());
            b.setNamaBrg(txtNamaBarang.getText());
            servicesBarang1.update(b);
        }
    
        private void delete(ServicesBarang servicesBarang1) throws RemoteException {
            Barang b = new Barang();
            b.setIdBrg(txtIDBarang.getText());
            servicesBarang1.delete(b);
        }
    
        private void panggilKategori(ServicesKategori servicesKategori1) throws RemoteException {
            List listKategori = new ArrayList<>();
            listKategori = servicesKategori1.getKategori();
            cbKategori.removeAllItems();
            for (int i = 0; i < listKategori.size(); i++) {
                cbKategori.addItem(listKategori.get(i).getKategori());
            }
        }
    
        public void Clear() {
            txtIDBarang.setText(null);
            txtNamaBarang.setText(null);
        }
    
        /**
         * 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")
    
        private void btnInsertActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            if (txtIDBarang.getText().equals("") || cbKategori.getSelectedItem().equals("") || txtNamaBarang.getText().equals("")) {
                JOptionPane.showMessageDialog(null, "Maaf, input data belum lengkap!");
            } else {
                try {
                    insert(servicesBarang);
                    select(servicesBarang);
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, e.getMessage());
                }
                Clear();
            }
        }
    
        private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            if (txtIDBarang.getText().equals("") || cbKategori.getSelectedItem().equals("") || txtNamaBarang.getText().equals("")) {
                JOptionPane.showMessageDialog(null, "Maaf, pilih data yang akan diupdate!");
            } else {
                try {
                    update(servicesBarang);
                    select(servicesBarang);
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, e.getMessage());
                }
                Clear();
            }
        }
    
        private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            if (txtIDBarang.getText().equals("") || cbKategori.getSelectedItem().equals("") || txtNamaBarang.getText().equals("")) {
                JOptionPane.showMessageDialog(null, "Maaf, pilih data yang akan didelete!");
            } else {
                try {
                    delete(servicesBarang);
                    select(servicesBarang);
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, e.getMessage());
                }
                Clear();
            }
        }
    
        private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            Clear();
        }
    
        private void tblBarangMouseClicked(java.awt.event.MouseEvent evt) {
            // TODO add your handling code here:
            txtIDBarang.setText(tblBarang.getValueAt(tblBarang.getSelectedRow(), 0).toString());
            cbKategori.setSelectedItem(tblBarang.getValueAt(tblBarang.getSelectedRow(), 1).toString());
            txtNamaBarang.setText(tblBarang.getValueAt(tblBarang.getSelectedRow(), 2).toString());
        }
    
        private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            new MainMenu(MainMenu.kondisiLogin).setVisible(true);
            this.dispose();
        }
    
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            /* Set the Nimbus look and feel */
            //
            /* 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 ("Windows".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(DaftarBarang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(DaftarBarang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(DaftarBarang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(DaftarBarang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //
    
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    try {
                        new DaftarBarang().setVisible(true);
                    } catch (RemoteException ex) {
                        Logger.getLogger(DaftarBarang.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (NotBoundException ex) {
                        Logger.getLogger(DaftarBarang.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            });
        }
        // Variables declaration - do not modify
        private javax.swing.JButton btnCancel;
        private javax.swing.JButton btnClose;
        private javax.swing.JButton btnDelete;
        private javax.swing.JButton btnEdit;
        private javax.swing.JButton btnInsert;
        private javax.swing.JComboBox cbKategori;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JPanel jPanel3;
        private javax.swing.JScrollPane jScrollPane2;
        private javax.swing.JTable tblBarang;
        private javax.swing.JTextField txtIDBarang;
        private javax.swing.JTextField txtNamaBarang;
        // End of variables declaration
    }
    
  29. Edit script pada class KategoriBarang seperti dibawah ini.
  30. /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package MiniMarket;
    
    import Entitas.Kategori;
    import Services.ServicesKategori;
    import java.rmi.NotBoundException;
    import java.rmi.RemoteException;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.registry.Registry;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.JOptionPane;
    import static javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE;
    import javax.swing.table.DefaultTableModel;
    
    /**
     *
     * @author AdhityaBEe
     */
    public class KategoriBarang extends javax.swing.JFrame {
    
        final ServicesKategori serviceKategori;
    
        /**
         * Creates new form KategoriBarang
         */
        public KategoriBarang() throws RemoteException, NotBoundException {
            Registry registry = LocateRegistry.getRegistry(1099);
            serviceKategori = (ServicesKategori) registry.lookup("kategori");
            initComponents();
            select(serviceKategori);
            this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        }
    
        private void select(ServicesKategori serviceKategori1) throws RemoteException {
            List listKategori = new ArrayList<>();
            String header[] = {"Kategori", "Deskripsi"};
            DefaultTableModel defaultTableModel = new DefaultTableModel(null, header);
            tblKategori.setModel(defaultTableModel);
            for (int i = 0; i < tblKategori.getRowCount(); i++) {
                defaultTableModel.removeRow(i);
            }
            listKategori = serviceKategori1.getKategori();
            for (int i = 0; i < listKategori.size(); i++) {
                Object baris[] = {listKategori.get(i).getKategori(), listKategori.get(i).getDeskripsi()};
                defaultTableModel.addRow(baris);
            }
        }
    
        private void insert(ServicesKategori serviceKategori1) throws RemoteException {
            Kategori k = new Kategori();
            k.setKategori(txtKategori.getText());
            k.setDeskripsi(txtDeskripsi.getText());
            serviceKategori1.insert(k);
        }
    
        private void update(ServicesKategori serviceKategori1) throws RemoteException {
            Kategori k = new Kategori();
            k.setKategori(txtKategori.getText());
            k.setDeskripsi(txtDeskripsi.getText());
            serviceKategori1.update(k);
        }
    
        private void delete(ServicesKategori serviceKategori1) throws RemoteException {
            Kategori k = new Kategori();
            k.setKategori(txtKategori.getText());
            serviceKategori1.delete(k);
        }
    
        public void Clear() {
            txtKategori.setText(null);
            txtDeskripsi.setText(null);
        }
    
        /**
         * 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")
    
        private void btnInsertActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            if (txtKategori.getText().equals("") || txtDeskripsi.getText().equals("")) {
                JOptionPane.showMessageDialog(null, "Maaf, input data belum lengkap!");
            } else {
                try {
                    insert(serviceKategori);
                    select(serviceKategori);
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, e.getMessage());
                }
                Clear();
            }
        }
    
        private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            Clear();
        }
    
        private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            if (txtKategori.getText().equals("") || txtDeskripsi.getText().equals("")) {
                JOptionPane.showMessageDialog(null, "Maaf, pilih data yang akan didelete!");
            } else {
                try {
                    delete(serviceKategori);
                    select(serviceKategori);
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, e.getMessage());
                }
                Clear();
            }
        }
    
        private void tblKategoriMouseClicked(java.awt.event.MouseEvent evt) {
            // TODO add your handling code here:
            txtKategori.setText(tblKategori.getValueAt(tblKategori.getSelectedRow(), 0).toString());
            txtDeskripsi.setText(tblKategori.getValueAt(tblKategori.getSelectedRow(), 1).toString());
        }
    
        private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            new MainMenu(MainMenu.kondisiLogin).setVisible(true);
            this.dispose();
        }
    
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            /* Set the Nimbus look and feel */
            //
            /* 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 ("Windows".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(KategoriBarang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(KategoriBarang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(KategoriBarang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(KategoriBarang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //
    
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    try {
                        new KategoriBarang().setVisible(true);
                    } catch (RemoteException ex) {
                        Logger.getLogger(KategoriBarang.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (NotBoundException ex) {
                        Logger.getLogger(KategoriBarang.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            });
        }
        // Variables declaration - do not modify
        private javax.swing.JButton btnCancel;
        private javax.swing.JButton btnClose;
        private javax.swing.JButton btnDelete;
        private javax.swing.JButton btnInsert;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JPanel jPanel3;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JScrollPane jScrollPane2;
        private javax.swing.JTable tblKategori;
        private javax.swing.JTextArea txtDeskripsi;
        private javax.swing.JTextField txtKategori;
        // End of variables declaration
    }
    
  31. Untuk menjalankan program Client Server ini, pertama yang harus dijalankan adalah Server.java pada project MiniMarket-Server.
  32. Setelah itu jalankan DaftarBarang pada project MiniMarket-Client.
  33. Berikut hasilnya:Untitled
  34. Selesai… :) jika masih gagal maka cek kembali code pada class-class yang dibuat, atau mungkin cek XAMPP sudah aktif atau belum. Selamat Mencoba!!!
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s