Sunday, January 27, 2013

Tutorial 6 Java2SE: Application Student's Information.

NIM       : 49012076
Name     : Chhorn Bros
Major     : TMD
Topic      : Talk about (Application Student Information).




Link to Video



Aplikasi Daftar Peta Jabatan Personel Militer dan PNS TNI AD




Ersus Saeful Hidayat
49012050

Sourcecode AppDPJPS Berbasis Client Server [RMI]



Link Video Youtube Klick disini.

Ø  Membuat 3 buah Project
1.      Project Java Class Library – DPJPS-API
2.      Project Java Aplication – DPJPS-SERVER
3.      Project Java Aplication – DPJPS-CLIENT

Setelah membuat 3 buah project include project [DPJPS-API] ke [DPJPS-SERVER] dan [DPJPS-CLIENT].
-          Dengan cara klik kana di project – DPJPS-SERVER -> Properties. Project Properties, pilih Categories Libraries -> Klik Add Project… -> pilih project DPJPS-API.
-          Lakukan yang sama dengan project DPJPS-CLIENT

Ø  Membuat Entitas – Project DPJSP-API
-          Isi project DPJPS-API dengam mulai membuat Java Package terlebih dahulu dengan nama [saeful.dpjpsapi.entity].
-          Setelah itu membuat Java Class Entitas dengan nama [Personel.java] yang akan digunakan di Project Server maupun Client.

Personel.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package saeful.dpjpsapi.entity;

import java.io.Serializable;
import java.util.Date;

/**
 *
 * @author MALIKA AZZAHRA
 */
public class Personel implements Serializable{ // membangun aplikasi menggunakan RMI //[implements Serializable]

    private Long no; //krn berbasis database harus ada unik id
    private String kelompok;
    private String nrp_nip;
    private String nama_personel;
    private String tempat_lahir;
    private Date tgl_lahir;
    private String agama;
    private String suku_bangsa;
    private String status;
    private String gol_darah;
 //[Source-Getter and Setter-check list semua]

    public String getStatus() {
        return status;
    }

    public void setStatus(String Status) {
        this.status = Status;
    }

    public String getAgama() {
        return agama;
    }

    public void setAgama(String agama) {
        this.agama = agama;
    }

    public String getGol_darah() {
        return gol_darah;
    }

    public void setGol_darah(String gol_darah) {
        this.gol_darah = gol_darah;
    }

    public String getKelompok() {
        return kelompok;
    }

    public void setKelompok(String kelompok) {
        this.kelompok = kelompok;
    }

    public String getNama_personel() {
        return nama_personel;
    }

    public void setNama_personel(String nama_personel) {
        this.nama_personel = nama_personel;
    }

    public Long getNo() {
        return no;
    }

    public void setNo(Long no) {
        this.no = no;
    }

    public String getNrp_nip() {
        return nrp_nip;
    }

    public void setNrp_nip(String nrp_nip) {
        this.nrp_nip = nrp_nip;
    }

    public String getSuku_bangsa() {
        return suku_bangsa;
    }

    public void setSuku_bangsa(String suku_bangsa) {
        this.suku_bangsa = suku_bangsa;
    }

    public String getTempat_lahir() {
        return tempat_lahir;
    }

    public void setTempat_lahir(String tempat_lahir) {
        this.tempat_lahir = tempat_lahir;
    }

    public Date getTgl_lahir() {
        return tgl_lahir;
    }

    public void setTgl_lahir(Date tgl_lahir) {
        this.tgl_lahir = tgl_lahir;
    }
}

Ø  Membuat Interface Service, dimana biasanya berupa data acces object
-          Buat kembali package di DPJPS-API dengan nama package [saeful.dpjpsapi.service]
-          Setelah itu buat Java Interface dengan nama [PersonelService.java]

PersonelService.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package saeful.dpjpsapi.service;

import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.List;
import saeful.dpjpsapi.entity.Personel;

/**
 *
 * @author MALIKA AZZAHRA
 */
public interface PersonelService extends Remote{ // Karena akan di sharing dari Server ke Client //[extends Remote]

    Personel insertPersonel(Personel personel)throws RemoteException;

    void updatePersonel(Personel personel)throws RemoteException;

    void deletePersonel(Long no)throws RemoteException;

    Personel getByNrpNip(String nrp_nip)throws RemoteException;

    List<Personel> getAll()throws RemoteException;

}

Ø  Membuat Database, XAMPP - php MyAdmin
Nama databse : db_dpjps
Dengan Tabel :
-          tb_personel
-          tb_jabatan
-          tb_pendidikan
-          tb_keluarga

Ø  Membuat Koneksi ke Database
Membuat koneksi ke database dilakukan pada aplikasi project DPJPS-SERVER, Client tidak akan pernah tahu sama sekali tentang proses ke database, hanya Server yang melakukan proses koneksi ke Database. Yang dilakukan Client hanya mereques ke Server setelah itu Server yang melakukan manipulasi data ke Database. DatabaseUtilities menggunakan static merupakan Class yang digunakan untuk menampung utilities-utilities database.
-          Membuat package dengan nama package [saeful.dpjpsserver.Utilities].
-          Membuat Java Class dengan nama [DatabaseUtilities.java]
-          Tambahkan MySQL JDBC Driver database ke Library, dengan cara klik kanan project DPJPS-SERVER -> Properties. Project Properties pilih Libraries –> klik Add Library -> pilih MySQL JDBC Driver lalu klik Add Library.

DatabaseUtilities.java

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

package saeful.dpjpsserver.Utilities;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author MALIKA AZZAHRA
 */
public class DatabaseUtilities {

    private static Connection connection;

    public static Connection getConnection(){

        if(connection == null){
            try {
                DriverManager.registerDriver(new com.mysql.jdbc.Driver());

                connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db_dpjps", "root", "");

            } catch (SQLException ex) {
                Logger.getLogger(DatabaseUtilities.class.getName()).log(Level.SEVERE, null, ex);
            }

        }

        return connection;
    }

}

Ø  Mengimplementasi Service Server dan Logger, implementasi DPJPS-SERVER dari project interface DPJPS-API [saeful.dpjpsapi.service][PersonelService.java]. Sekarang implementasinya di project DPJPS-SERVER.
-          Dengan membuat package baru [saeful.dpjpsserver.service], lalu membuat Java Class dengan nama [PersonelServiceServer.java].

PersonelServiceServer.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package saeful.dpjpsserver.service;

import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.Statement;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import saeful.dpjpsapi.entity.Personel;
import saeful.dpjpsapi.service.PersonelService;
import saeful.dpjpsserver.Utilities.DatabaseUtilities;

/**
 *
 * @author MALIKA AZZAHRA
 */
//janagn lupa extends UnicastRemoteObject implements PersonelService
public class PersonelServiceServer extends UnicastRemoteObject implements PersonelService{
//klik implement all abstract methods
//Setelah itu buat contruktor, klik source -> insert code -> pilih Constructor -> checklist [UnicastRemoteObject()]

    public PersonelServiceServer() throws RemoteException {
    }

    public Personel insertPersonel(Personel personel) throws RemoteException {

// Logger, saat client melakukan reques methods ini maka server akan mentres pesan ini.

        System.out.println("Client Melakukan Proses Insert Personel ");
        PreparedStatement statement = null;

        try{
            statement = (PreparedStatement) DatabaseUtilities.getConnection().prepareStatement(
                    "INSERT INTO tb_personel(no, kelompok, nrp_nip, nama_personel, tempat_lahir, tgl_lahir, agama, suku_bangsa, status, gol_darah) VALUES(null, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
                    );

            statement.setString(1, personel.getKelompok());
            statement.setString(2, personel.getNrp_nip());
            statement.setString(3, personel.getNama_personel());
            statement.setString(4, personel.getTempat_lahir());
            statement.setDate(5, new Date(personel.getTgl_lahir().getTime()));
            statement.setString(6, personel.getAgama());
            statement.setString(7, personel.getSuku_bangsa());
            statement.setString(8, personel.getStatus());
            statement.setString(9, personel.getGol_darah());

            statement.executeUpdate();

            ResultSet result = statement.getGeneratedKeys();

            if(result.next()){
                personel.setNo(result.getLong(1));
            }
            result.close();
            return personel;

        }catch(SQLException exception){
            exception.printStackTrace();
            return null;

        }finally{
            if(statement != null){
                try{
                    statement.close();
                }catch(SQLException exception){

                }
            }
        }

    }

    public void updatePersonel(Personel personel) throws RemoteException {

        System.out.println("Client Melakukan Proses Update Personel");

        PreparedStatement statement = null;

        try{
            statement = (PreparedStatement) DatabaseUtilities.getConnection().prepareStatement(
                    "UPDATE tb_personel SET kelompok = ?, nrp_nip = ?, nama_personel = ?, tempal_lahir = ?, tgl_lahir = ?, agama = ?, suku_bangsa = ?, status = ?, gol_darah = ? WHERE no = ?"
                    );

            statement.setString(1, personel.getKelompok());
            statement.setString(2, personel.getNrp_nip());
            statement.setString(3, personel.getNama_personel());
            statement.setString(4, personel.getTempat_lahir());
            statement.setDate(5, new Date(personel.getTgl_lahir().getTime()));
            statement.setString(6, personel.getAgama());
            statement.setString(7, personel.getSuku_bangsa());
            statement.setString(8, personel.getStatus());
            statement.setString(9, personel.getGol_darah());
            statement.setLong(10, personel.getNo());

            statement.executeUpdate();

        }catch(SQLException exception){
            exception.printStackTrace();
        }finally{
            if(statement != null){
                try{
                    statement.close();
                }catch(SQLException exception){
                    exception.printStackTrace();
                }

            }
        }

    }

    public void deletePersonel(Long no) throws RemoteException {

        System.out.println("Client Melakukan Proses Delete Personel");

        PreparedStatement statement = null;

        try{
            statement = (PreparedStatement) DatabaseUtilities.getConnection().prepareStatement(
                    "DELETE FROM tb_personel WHERE no = ?"
                    );

            statement.setLong(1, no);

            statement.executeUpdate();

        }catch(SQLException exception){
            exception.printStackTrace();
        }finally{
            if(statement != null){
                try{
                    statement.close();
                }catch(SQLException exception){
                    exception.printStackTrace();
                }
            }
        }

    }

    public Personel getByNrpNip(String nrp_nip) throws RemoteException {
       
        System.out.println("Client Melakukan Proses GetByNrpNip Personel");

        PreparedStatement statement = null;

        try{

            statement = (PreparedStatement) DatabaseUtilities.getConnection().prepareStatement(
                    "SELECT * FROM tb_personel WHERE nrp_nip = ?"
                    );

            ResultSet result = statement.executeQuery();

            Personel personel = null;

            if(result.next()){
                personel = new Personel();
                personel.setNo(result.getLong("no"));
                personel.setKelompok(result.getString("kelompok"));
                personel.setNrp_nip(result.getString("nrp_nip"));
                personel.setNama_personel(result.getString("nama_personel"));
                personel.setTempat_lahir(result.getString("tempat_lahir"));
                personel.setTgl_lahir(result.getDate("tgl_lahir"));
                personel.setAgama(result.getString("agama"));
                personel.setSuku_bangsa(result.getString("suku_bangsa"));
                personel.setStatus(result.getString("status"));
                personel.setGol_darah(result.getString("gol_darah"));
            }

            result.close();
            return personel;

        }catch(SQLException exception){
            exception.printStackTrace();

            return null;

        }finally{
            if(statement != null){
                try{
                    statement.close();
                }catch(SQLException exception){
                    exception.printStackTrace();
                }
            }
        }
    }

    public List<Personel> getAll() throws RemoteException {
       
        System.out.println("Client Melakukan Proses GetAll Personel");

        Statement statement = null;

        try{

            statement = (Statement) DatabaseUtilities.getConnection().createStatement();

            ResultSet result = statement.executeQuery(
                    "SELECT * FROM tb_personel"
                    );

            List<Personel> list = new ArrayList<Personel>();

            while(result.next()){

                Personel personel = new Personel();
                personel.setNo(result.getLong("no"));
                personel.setKelompok(result.getString("kelompok"));
                personel.setNrp_nip(result.getString("nrp_nip"));
                personel.setNama_personel(result.getString("nama_personel"));
                personel.setTempat_lahir(result.getString("tempat_lahir"));
                personel.setTgl_lahir(result.getDate("tgl_lahir"));
                personel.setAgama(result.getString("agama"));
                personel.setSuku_bangsa(result.getString("suku_bangsa"));
                personel.setStatus(result.getString("status"));
                personel.setGol_darah(result.getString("gol_darah"));

                list.add(personel);
            }

            result.close();

            return list;

        }catch(SQLException exception){
            exception.printStackTrace();

            return null;

        }finally{
            if(statement != null){
                try{
                    statement.close();
                }catch(SQLException exception){
                    exception.printStackTrace();
                }
            }
        }
    }
}


Ø  Membuat Aplikasi Server
Aplikasi server dibuat di package [saeful.dpjpsserver] di Java Main Class [main.java ]

Main.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package saeful.dpjpsserver;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import saeful.dpjpsserver.service.JabatanServiceServer;
import saeful.dpjpsserver.service.KeluargaServiceServer;
import saeful.dpjpsserver.service.PendidikanServiceServer;
import saeful.dpjpsserver.service.PersonelServiceServer;

/**
 *
 * @author MALIKA AZZAHRA
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws RemoteException {
        // TODO code application logic here
        // port server
        Registry server = LocateRegistry.createRegistry(3904);

        PersonelServiceServer personelService = new PersonelServiceServer();
        server.rebind("personelService", personelService);

        JabatanServiceServer jabatanService = new JabatanServiceServer();
        server.rebind("jabatanService", jabatanService);

        PendidikanServiceServer pendidikanService = new PendidikanServiceServer();
        server.rebind("pendidikanService", pendidikanService);

        KeluargaServiceServer keluargaService = new KeluargaServiceServer();
        server.rebind("keluargaService", keluargaService);

        System.out.println("Server Berhasil Berjalan");

    }

}

Ø  Membuat Table Model, digunak sebagi model pada table.
Pada project DPJPS-CLIENT, buat package baru dengan nama [saeful.dpjpsclient.model] lalu buat Java Class [TableModelPersonel.java]

TableModelPersonel.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package saeful.dpjpsclient.model;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import saeful.dpjpsapi.entity.Personel;

/**
 *
 * @author MALIKA AZZAHRA
 */
public class TableModelPersonel extends AbstractTableModel{

//Klik implement all abstrack methods

    private List<Personel> list = new ArrayList<Personel>();

    public TableModelPersonel() {
    }

    public Personel get(int row){
        return list.get(row);
    }

    public void insert(Personel personel){
        list.add(personel);
        fireTableDataChanged(); // Untuk memberitahu klo ada perubahan data
    }

    public void update(int row, Personel personel){
        list.set(row, personel);
        fireTableDataChanged();
    }

    public void delete(int row){
        list.remove(row);
        fireTableDataChanged();
    }

    public void setData(List<Personel> list){
        this.list = list;
        fireTableDataChanged();
    }

    @Override
    public String getColumnName(int column){
        switch(column){
            case 0:return "NO";
            case 1:return "KELOMPOK";
            case 2:return "NRP/NIP";
            case 3:return "NAMA PERSONEL";
            case 4:return "TEMPAT LAHIR";
            case 5:return "TGL LAHIR";
            case 6:return "AGAMA";
            case 7:return "SUKU BANGSA";
            case 8:return "STATUS";
            case 9:return "GOL DARAH";
            default:return null;
        }
    }

    public int getRowCount() {
        return list.size();
    }

    public int getColumnCount() {
        return 10;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        switch(columnIndex){
            case 0:return list.get(rowIndex).getNo();
            case 1:return list.get(rowIndex).getKelompok();
            case 2:return list.get(rowIndex).getNrp_nip();
            case 3:return list.get(rowIndex).getNama_personel();
            case 4:return list.get(rowIndex).getTempat_lahir();
            case 5:return list.get(rowIndex).getTgl_lahir();
            case 6:return list.get(rowIndex).getAgama();
            case 7:return list.get(rowIndex).getSuku_bangsa();
            case 8:return list.get(rowIndex).getStatus();
            case 9:return list.get(rowIndex).getGol_darah();
            default:return null;

        }
    }

}

Ø  Membuat Form Client

-          Buat fackage baru dengan nama package [saeful.dpjpsclient.form][FormUtama.java]
-         



Buat form baru dengan jFrame Form dengan nama [FormUtama.java]

FormUtama.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FormUtama.java
 *
 * Created on Jan 3, 2013, 10:28:29 AM
 */

package saeful.dpjpsclient.form;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import saeful.dpjpsapi.service.JabatanService;
import saeful.dpjpsapi.service.KeluargaService;
import saeful.dpjpsapi.service.PendidikanService;
import saeful.dpjpsapi.service.PersonelService;

/**
 *
 * @author MALIKA AZZAHRA
 */
public class FormUtama extends javax.swing.JFrame {
   
    PersonelService personelService;
    JabatanService jabatanService;
    PendidikanService pendidikanService;
    KeluargaService keluargaService;

    /** Creates new form FormUtama */
    public FormUtama(PersonelService personelService, JabatanService jabatanService, PendidikanService pendidikanService, KeluargaService keluargaService) {

        this.personelService = personelService;
        this.jabatanService = jabatanService;
        this.pendidikanService = pendidikanService;
        this.keluargaService = keluargaService;

        initComponents();
        jam();
        this.setMenu(false);
    }

    void setMenu(boolean  status){
        jMenuDataInput.setVisible(status);
        jMenuDataTampilan.setVisible(status);
        jMenuItemLogout.setVisible(status);
        jLabelInputDataPersonel.setVisible(status);
        jLabelInputDataJabatan.setVisible(status);
        jLabelInputDataPendidikan.setVisible(status);
        jLabelInputDataKeluarga.setVisible(status);
        jLabelLogout.setVisible(status);
       
    }

    /** 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">                         
    ……
    }// </editor-fold>                       

    private void jMenuItemLoginActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
        login();
    }                                             

    private void jButtonLoginActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
        Userlogin();
    }                                           

    private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
        jDialogLogin.setVisible(false);
    }                                             

    private void jMenuItemLogoutActionPerformed(java.awt.event.ActionEvent evt) {                                               
        // TODO add your handling code here:
        logout();
    }                                              

    private void jMenuItemExitActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
        System.exit(1);
    }                                            

    private void jMenuItemInputDataPersonelActionPerformed(java.awt.event.ActionEvent evt) {                                                          
        // TODO add your handling code here:
        inputDataPersonel();
    }                                                          

    private void jMenuItemInputDataJabatanActionPerformed(java.awt.event.ActionEvent evt) {                                                         
        // TODO add your handling code here:
        inputDataJabatan();
    }                                                         

    private void jMenuItemInputDataPendidikanActionPerformed(java.awt.event.ActionEvent evt) {                                                            
        // TODO add your handling code here:
        inputDataPendidikan();
    }                                                           

    private void jMenuItemInputDataKeluargaActionPerformed(java.awt.event.ActionEvent evt) {                                                          
        // TODO add your handling code here:
        inputDataKeluarga();
    }                                                         

    private void jMenuItemTampilanDataDPJPSActionPerformed(java.awt.event.ActionEvent evt) {                                                           
        // TODO add your handling code here:
        TampilDataDPJPS();
    }                                                         

    private void jButtonResetActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
        Username.setText(null);
        Password.setText(null);

    }                                           

    private void jLabelExitMouseClicked(java.awt.event.MouseEvent evt) {                                       
        // TODO add your handling code here:
        System.exit(0);
    }                                      

    private void jLabelLogoutMouseClicked(java.awt.event.MouseEvent evt) {                                          
        // TODO add your handling code here:
        logout();
    }                                        

    private void jLabelLoginMouseClicked(java.awt.event.MouseEvent evt) {                                        
        // TODO add your handling code here:
        login();
    }                                       

    private void jMenuDataTampilanActionPerformed(java.awt.event.ActionEvent evt) {                                                 
        // TODO add your handling code here:
        TampilDataDPJPS();
    }                                                

    private void jLabelInputDataPersonelMouseClicked(java.awt.event.MouseEvent evt) {                                                    
        // TODO add your handling code here:
        inputDataPersonel();
    }                                                    

    private void jLabelInputDataJabatanMouseClicked(java.awt.event.MouseEvent evt) {                                                   
        // TODO add your handling code here:
        inputDataJabatan();
    }                                                   

    private void jLabelInputDataPendidikanMouseClicked(java.awt.event.MouseEvent evt) {                                                      
        // TODO add your handling code here:
        inputDataPendidikan();
    }                                                      

    private void jLabelInputDataKeluargaMouseClicked(java.awt.event.MouseEvent evt) {                                                    
        // TODO add your handling code here:
        inputDataKeluarga();
    }                                                   

    /**
    * @param args the command line arguments
    */

    public void Userlogin(){
        if (Username.getText().equals("admin") && Password.getText().equals("admin")){
            this.setMenu(true);
            Username.setText("");
            Password.setText("");
            jDialogLogin.setVisible(false);
            jMenuItemLogin.hide();
            jLabelLogin.hide();
        }       
    }

    public void login(){
        jDialogLogin.setSize(530, 370);
        jDialogLogin.setLocationRelativeTo(null);
        jDialogLogin.setVisible(true);
    }

    public void logout(){
        this.setMenu(false);
        jDesktopPaneMenuUtama.removeAll();
        jDesktopPaneMenuUtama.disable();
        jMenuItemLogin.show();
        jLabelLogin.show();
    }

    public void inputDataPersonel(){
        FormPersonel formPersonel = new FormPersonel(personelService);
        jDesktopPaneMenuUtama.disable();
        jDesktopPaneMenuUtama.removeAll();
        formPersonel.setVisible(true);
        jDesktopPaneMenuUtama.add(formPersonel);
        jDesktopPaneMenuUtama.enable();
    }

    public void inputDataJabatan(){
        FormJabatan formJabatan = new FormJabatan(jabatanService);
        jDesktopPaneMenuUtama.disable();
        jDesktopPaneMenuUtama.removeAll();
        formJabatan.setVisible(true);
        jDesktopPaneMenuUtama.add(formJabatan);
        jDesktopPaneMenuUtama.enable();
    }

    public void inputDataPendidikan(){
        FormPendidikan formPendidikan = new FormPendidikan(pendidikanService);
        jDesktopPaneMenuUtama.disable();
        jDesktopPaneMenuUtama.removeAll();
        formPendidikan.setVisible(true);
        jDesktopPaneMenuUtama.add(formPendidikan);
        jDesktopPaneMenuUtama.enable();
    }

    public void inputDataKeluarga(){
        FormKeluarga formKeluarga = new FormKeluarga(keluargaService);
        jDesktopPaneMenuUtama.disable();
        jDesktopPaneMenuUtama.removeAll();
        formKeluarga.setVisible(true);
        jDesktopPaneMenuUtama.add(formKeluarga);
        jDesktopPaneMenuUtama.enable();
    }

    public void TampilDataDPJPS(){
        TampilDPJPS tampilPersonel = new TampilDPJPS();
        jDesktopPaneMenuUtama.disable();
        jDesktopPaneMenuUtama.removeAll();
        tampilPersonel.setVisible(true);
        jDesktopPaneMenuUtama.add(tampilPersonel);
        jDesktopPaneMenuUtama.enable();
    }

    public void jam(){
        ActionListener taskPerformer = new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
        String nol_jam = "";
        String nol_menit = "";
        String nol_detik = "";
        Date dt = new Date();
        int tgl = dt.getDate();
        int bln = dt.getMonth();
        int thn = dt.getYear();
        int hari = dt.getDay();
        int nilai_jam = dt.getHours();
        int nilai_menit = dt.getMinutes();
        int nilai_detik = dt.getSeconds();
        if (nilai_jam <= 9) {
          nol_jam = "0";
        }
        if (nilai_menit <= 9) {
          nol_menit = "0";
        }
        if (nilai_detik <= 9) {
          nol_detik = "0";
        }
        String jam = nol_jam + Integer.toString(nilai_jam);
        String menit = nol_menit + Integer.toString(nilai_menit);
        String detik = nol_detik + Integer.toString(nilai_detik);
        jLabelJamSekarang.setText("  " + jam + " : " + menit + " : " + detik + "  ");
      }
    };
    new javax.swing.Timer(1000, taskPerformer).start();
    }

    // Variables declaration - do not modify                    
    private javax.swing.JPasswordField Password;
    private javax.swing.JTextField Username;
    private javax.swing.JButton jButtonCancel;
    private javax.swing.JButton jButtonLogin;
    private javax.swing.JButton jButtonReset;
    private javax.swing.JDesktopPane jDesktopPaneMenuUtama;
    private javax.swing.JDialog jDialogLogin;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabelExit;
    private javax.swing.JLabel jLabelInputDataJabatan;
    private javax.swing.JLabel jLabelInputDataKeluarga;
    private javax.swing.JLabel jLabelInputDataPendidikan;
    private javax.swing.JLabel jLabelInputDataPersonel;
    private javax.swing.JLabel jLabelJamSekarang;
    private javax.swing.JLabel jLabelLogin;
    private javax.swing.JLabel jLabelLogout;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenuBar jMenuBar;
    private javax.swing.JMenuBar jMenuBar2;
    private javax.swing.JMenu jMenuDataInput;
    private javax.swing.JMenu jMenuDataTampilan;
    private javax.swing.JMenu jMenuFile;
    private javax.swing.JMenuItem jMenuItemExit;
    private javax.swing.JMenuItem jMenuItemInputDataJabatan;
    private javax.swing.JMenuItem jMenuItemInputDataKeluarga;
    private javax.swing.JMenuItem jMenuItemInputDataPendidikan;
    private javax.swing.JMenuItem jMenuItemInputDataPersonel;
    private javax.swing.JMenuItem jMenuItemLogin;
    private javax.swing.JMenuItem jMenuItemLogout;
    private javax.swing.JMenuItem jMenuItemTampilanDataDPJPS;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JFormattedTextField tglFormat;
    // End of variables declaration                  

}

Ø  FormPersonel.java [JInternalFrame]




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

/*
 * FormPersonel.java
 *
 * Created on Jan 5, 2013, 9:33:18 PM
 */

package saeful.dpjpsclient.form;

import com.itextpdf.text.DocumentException;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterJob;
import java.io.FileWriter;
import java.io.IOException;
import java.rmi.RemoteException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import saeful.dpjpsapi.entity.Personel;
import saeful.dpjpsapi.service.PersonelService;
import saeful.dpjpsclient.model.TableModelPersonel;

/**
 *
 * @author MALIKA AZZAHRA
 */
public class FormPersonel extends javax.swing.JInternalFrame {

    private TableModelPersonel tableModelPersonel = new TableModelPersonel();
    private PersonelService personelService;
    private Personel personel = new Personel();

    /** Creates new form FormPersonel */
    public FormPersonel(PersonelService personelService) {

        this.personelService = personelService;

        try{
            tableModelPersonel.setData(this.personelService.getAll());// agar saat pertamakali berjalan tabel manmpilkan database
        }catch(RemoteException exception){
            exception.printStackTrace();
        }

        initComponents();

        jTablePersonel.setModel(tableModelPersonel);

        jTablePersonel.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            public void valueChanged(ListSelectionEvent e) {
                int row = jTablePersonel.getSelectedRow();
                if(row != -1){

                    Personel personel = tableModelPersonel.get(row);

                    jComboBoxKelompok.setSelectedItem(personel.getKelompok());
                    jTextFieldNrpNip.setText(personel.getNrp_nip());
                    jTextFieldNamaPersonel.setText(personel.getNama_personel());
                    jTextFieldTempatLahir.setText(personel.getTempat_lahir());
                    jDateChooserTglLahir.setDate(personel.getTgl_lahir());
                    jComboBoxAgama.setSelectedItem(personel.getAgama());
                    jComboBoxSukuBangsa.setSelectedItem(personel.getSuku_bangsa());
                    jComboBoxStatus.setSelectedItem(personel.getStatus());
                    jComboBoxGolDarah.setSelectedItem(personel.getGol_darah());
                }

            }
        });
    }

    /** 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">                         
  …….
    }// </editor-fold>                        

    private void jButtonRefreshActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
        refresh();
    }                                              

    private void jButtonInsertActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
        insert();
    }                                            

    private void jButtonUpdateActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
        update();
    }                                            

    private void jButtonDeleteActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
        delete();
    }                                            

    private void jButtonExportToExcelActionPerformed(java.awt.event.ActionEvent evt) {                                                    
        // TODO add your handling code here:
        try {
            ExportToExcel();
            JOptionPane.showMessageDialog(null, "Berhasil Export To Excel Lokasi D:\\Rekap-" + jComboBoxCariGolDarah.getSelectedItem().toString() + ".csv");
        }catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, "Error Export To Excel");
        }
    }                                                    

    private void jButtonExportToPDFActionPerformed(java.awt.event.ActionEvent evt) {                                                  
        // TODO add your handling code here:
        try {
            ExportToPdf();
            JOptionPane.showMessageDialog(null, "Berhasil Export PDF");
        } catch (DocumentException ex) {
            JOptionPane.showMessageDialog(null, "Error Export to PDF");
        }
    }                                                 

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        refresh();
    }                                       

    private void jButtonPrintActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
        Print();
    }                                           

    private void jButtonNewActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        NewData();
    }                                         


    void NewData() {
        jComboBoxKelompok.setSelectedItem(null);
        jTextFieldNrpNip.setText("");
        jTextFieldNamaPersonel.setText("");
        jTextFieldTempatLahir.setText("");
        jDateChooserTglLahir.setDate(null);
        jComboBoxAgama.setSelectedItem(null);
        jComboBoxSukuBangsa.setSelectedItem(null);
        jComboBoxGolDarah.setSelectedItem(null);
        jComboBoxStatus.setSelectedItem(null);
    }

    public void refresh(){
        try{
            List<Personel> list = personelService.getAll();
            tableModelPersonel.setData(list);
        }catch(RemoteException exception){
            exception.printStackTrace();
        }
    }

    public void insert(){
        try{
            Personel personel = new Personel();
            personel.setKelompok(jComboBoxKelompok.getSelectedItem().toString());
            personel.setNrp_nip(jTextFieldNrpNip.getText());
            personel.setNama_personel(jTextFieldNamaPersonel.getText());
            personel.setTempat_lahir(jTextFieldTempatLahir.getText());
            personel.setTgl_lahir(jDateChooserTglLahir.getDate());
            personel.setAgama(jComboBoxAgama.getSelectedItem().toString());
            personel.setSuku_bangsa(jComboBoxSukuBangsa.getSelectedItem().toString());
            personel.setStatus(jComboBoxStatus.getSelectedItem().toString());
            personel.setGol_darah(jComboBoxGolDarah.getSelectedItem().toString());

            Personel personel1 = personelService.insertPersonel(personel);

            tableModelPersonel.insert(personel1);

        }catch(RemoteException exception){
            exception.printStackTrace();
        }       
    }

    public void update(){
        try{
            int row = jTablePersonel.getSelectedRow();
            if(row == -1){
                return;
            }

            Personel personel = tableModelPersonel.get(row);
            personel.setKelompok(jComboBoxKelompok.getSelectedItem().toString());
            personel.setNrp_nip(jTextFieldNrpNip.getText());
            personel.setNama_personel(jTextFieldNamaPersonel.getText());
            personel.setTempat_lahir(jTextFieldTempatLahir.getText());
            personel.setTgl_lahir(jDateChooserTglLahir.getDate());
            personel.setAgama(jComboBoxAgama.getSelectedItem().toString());
            personel.setSuku_bangsa(jComboBoxSukuBangsa.getSelectedItem().toString());
            personel.setStatus(jComboBoxStatus.getSelectedItem().toString());
            personel.setGol_darah(jComboBoxGolDarah.getSelectedItem().toString());

            personelService.updatePersonel(personel);

            tableModelPersonel.update(row, personel);

        }catch(RemoteException exception){
            exception.printStackTrace();
        }
    }

    public void delete(){
        try{

            int row = jTablePersonel.getSelectedRow();
            if(row == -1){
                return;
            }

            Long no = tableModelPersonel.get(row).getNo();

            personelService.deletePersonel(no);

        }catch(RemoteException exception){
            exception.printStackTrace();
        }
    }


    public void ExportToExcel(){
        FileWriter writer = null;
        try {
            writer = new FileWriter("D:\\Rekap-" + jComboBoxCariGolDarah.getSelectedItem().toString() + ".csv");
            writer.append("DATA "+jComboBoxCariGolDarah.getSelectedItem().toString());writer.append(',');
            writer.append('\n');
            writer.append('\n');
            writer.append("No");writer.append(',');
            writer.append("KELOMPOK");writer.append(',');
            writer.append("NRP/NIP");writer.append(',');
            writer.append("NAMA");writer.append(',');
            writer.append("TEMPAT");writer.append(',');
            writer.append("TGL LAHIR");writer.append(',');
            writer.append("AGAMA");writer.append(',');
            writer.append("SUKU BANGSA");writer.append(',');
            writer.append("STATUS");writer.append(',');
            writer.append("GOL DARAH");writer.append(',');
            writer.append('\n');
            int a = jTablePersonel.getSelectedRowCount();
            for(int i=0;i<=a*2;i++)
            {
                writer.append(jTablePersonel.getValueAt(i, 0).toString());writer.append(',');
                writer.append(jTablePersonel.getValueAt(i, 1).toString());writer.append(',');
                writer.append(jTablePersonel.getValueAt(i, 2).toString());writer.append(',');
                writer.append(jTablePersonel.getValueAt(i, 3).toString());writer.append(',');
                writer.append(jTablePersonel.getValueAt(i, 4).toString());writer.append(',');
                writer.append(jTablePersonel.getValueAt(i, 5).toString());writer.append(',');
                writer.append(jTablePersonel.getValueAt(i, 6).toString());writer.append(',');
                writer.append(jTablePersonel.getValueAt(i, 7).toString());writer.append(',');
                writer.append(jTablePersonel.getValueAt(i, 8).toString());writer.append(',');
                writer.append(jTablePersonel.getValueAt(i, 9).toString());writer.append(',');
                writer.append('\n');
            }
            writer.flush();
            writer.close();
        } catch (IOException ex) {
            Logger.getLogger(FormPersonel.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                writer.close();
            } catch (IOException ex) {
                Logger.getLogger(FormPersonel.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public void ExportToPdf() throws DocumentException{

    }

    public void Print(){
        PrinterJob printerJob = PrinterJob.getPrinterJob();
        PageFormat pageFormat = printerJob.pageDialog(printerJob.defaultPage());
        printerJob.setPrintable((Printable) this);
        try {
            if(printerJob.printDialog()) {
                printerJob.print();
            }
        } catch(Exception e) {

        }
    }
    // Variables declaration - do not modify                    
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonDelete;
    private javax.swing.JButton jButtonExportToExcel;
    private javax.swing.JButton jButtonExportToPDF;
    private javax.swing.JButton jButtonInsert;
    private javax.swing.JButton jButtonNew;
    private javax.swing.JButton jButtonPrint;
    private javax.swing.JButton jButtonRefresh;
    private javax.swing.JButton jButtonUpdate;
    private javax.swing.JComboBox jComboBoxAgama;
    private javax.swing.JComboBox jComboBoxCariGolDarah;
    private javax.swing.JComboBox jComboBoxCariKelompok;
    private javax.swing.JComboBox jComboBoxGolDarah;
    private javax.swing.JComboBox jComboBoxKelompok;
    private javax.swing.JComboBox jComboBoxStatus;
    private javax.swing.JComboBox jComboBoxSukuBangsa;
    private com.toedter.calendar.JDateChooser jDateChooserTglLahir;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTablePersonel;
    private javax.swing.JTextField jTextFieldNamaPersonel;
    private javax.swing.JTextField jTextFieldNrpNip;
    private javax.swing.JTextField jTextFieldTempatLahir;
    // End of variables declaration                  

}

 

Ø FormJabatan.java
Sourcecode nya hamper sama dengan FormPersonel

Ø FormPendidikan.java
Sourcecode nya hamper sama dengan FormPersonel

Ø FormKeluarga.java
Sourcecode nya hamper sama dengan FormPersonel



Ø  Membuat Aplikasi Client
Aplikasi Client dibuat di package [saeful.dpjpsclient] di Java Main Class [main.java ]
               
Main.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package saeful.dpjpsclient;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.nimbus.NimbusLookAndFeel;
import saeful.dpjpsapi.service.JabatanService;
import saeful.dpjpsapi.service.KeluargaService;
import saeful.dpjpsapi.service.PendidikanService;
import saeful.dpjpsapi.service.PersonelService;
import saeful.dpjpsclient.form.FormUtama;

/**
 *
 * @author MALIKA AZZAHRA
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)throws RemoteException, NotBoundException, MalformedURLException, UnsupportedLookAndFeelException {
        // TODO code application logic here
        //Alamat dan Port Client

        String host = "localhost";
        String port = "3904";

        //Registry registry = LocateRegistry.getRegistry("host", 3904);

        final PersonelService personelService =(PersonelService) Naming.lookup("rmi://"+host+":"+port+"/personelService");
        final JabatanService jabatanService =(JabatanService) Naming.lookup("rmi://"+host+":"+port+"/jabatanService");
        final PendidikanService pendidikanService =(PendidikanService) Naming.lookup("rmi://"+host+":"+port+"/pendidikanService");
        final KeluargaService keluargaService =(KeluargaService) Naming.lookup("rmi://"+host+":"+port+"/keluargaService");

        System.out.println("Client Berhasil Berjalan");

        try {
            UIManager.setLookAndFeel(new NimbusLookAndFeel());
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                try {
                    FormUtama formUtama = new FormUtama(personelService, jabatanService, pendidikanService, keluargaService);
                    formUtama.setExtendedState(JFrame.MAXIMIZED_BOTH);
                    formUtama.setLocationRelativeTo(null);
                    formUtama.setVisible(true);
                } catch (Throwable ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

}




Menjalankan Aplikasi DPJPS Client Server





Terimakasih. Semoga Bermanfaat.