Belajar MVC (model view controller) di java part 1

ya kali ini q mw share tentang MVC (model view controller) di java. btw ne posting ga diperuntukkan untuk profesional artikel ini untuk para begginer di java kayak aku,,,:[. Oke untuk mengetahui mengenai pengertian mvc sendiri kamu bisa liat di link ini: http://komputerjava.blogspot.com/2009/01/pengertian-model-view-controller-mvc_29.html
aku hanya akan membahas contoh codingnya ja, oke langsung kita mulai saja daripada terlalu lama.

1. buat kelas model.
import java.util.ArrayList;

public class DaftarInputModel {
private int id;
private String nama;
private String password;
private String repassword;
private String keterangan;

private ArrayList listener = new ArrayList(10);

public DaftarInputModel(){
}

//metod
public int getID(){
return id;
}
public String getNAMA(){
return nama;
}
public String getPASSWORD(){
return password;
}
public String getREPASSWORD(){
return repassword;
}
public String getKETERANGAN(){
return keterangan;
}

//methode set
public void setID(int ID){
this.id = ID;
}
public void setNAMA(String NAMA){
this.nama = NAMA;
}
public void setPASSWORD(String PASSWORD){
this.password = PASSWORD;
}
public void setREPASSWORD(String REPASSWORD){
this.repassword = REPASSWORD;
}
public void setKETERANGAN(String KETERANGAN ){
this.keterangan = KETERANGAN;
}

//metode lain
public void addModelChangeListener(Object view){
listener.add(view);
}
public void removeModelChangeListener(Object view){
listener.remove(view);
}

private void fireModelChangeEvent(Object o){

}
}

2. buat class controller
import privatepicture2.Model.DaftarInputModel;
import privatepicture2.View.DaftarForm;

public class DaftarInputController {
private DaftarInputModel model;
private DaftarForm view;

public DaftarInputController(DaftarInputModel model,DaftarForm view){
this.model = model;
this.view = view;
view.addUserGestureListener(this);
}

//methode
public void processGetID(){
model.getID();
}
public void processGetNAMA(){
model.getNAMA();
}
public void processGetPASSWORD(){
model.getPASSWORD();
}
public void processGetREPASSWORD(){
model.getREPASSWORD();
}
public void processGetKETERANGAN(){
model.getKETERANGAN();
}

//methode update
public void processUpdateID(int id){
model.setID(id);
}
public void processUpdateNAMA(String nama){
model.setNAMA(nama);
}
public void processUpdatePASSWORD(String password){
model.setPASSWORD(password);
}
public void processUpdateREPASSWORD(String repassword){
model.setREPASSWORD(repassword);
}
public void processUpdateKETERANGAN(String keterangan){
model.setKETERANGAN(keterangan);
}

}

3. buat class view

bersambungg……………………….

One thought on “Belajar MVC (model view controller) di java part 1

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