Web hosting

Tugas Mobile Computing - Pertemuan 03

berikut ini contoh aplikasi mobile untuk form inputan,


    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.util.Date;
   
public class inputdata extends MIDlet implements CommandListener {
    Display display;
    Form input;
    Alert warning;
    TextField nama, alamat, telp, email;
    DateField tgl;
    ChoiceGroup gender;
    StringItem text;
    Command exit = new Command("Exit", Command.EXIT, 1);
    Command view = new Command("View", Command.OK, 1);
   
    public inputdata(){
       input = new Form("Input Data");
       input.addCommand(exit);
       input.addCommand(view);
       input.setCommandListener(this);
       Date now = new Date();
      
       nama = new TextField("Nama", "", 32, TextField.ANY);
       gender = new ChoiceGroup("Gender", Choice.POPUP);
       gender.append("Laki-Laki", null);
       gender.append("Perempuan", null);
       alamat = new TextField("Alamat", "", 32, TextField.ANY);
       telp = new TextField("No Hp/telp", "", 32, TextField.PHONENUMBER);
       email = new TextField("E-mail", "", 32, TextField.EMAILADDR);
       tgl = new DateField("Tanggal Lahir", DateField.DATE);
       tgl.setDate(new Date());
      
       warning = new Alert("Alert Warning","harus terisi semua",null,AlertType.WARNING);
       warning.setTimeout(Alert.FOREVER);
      
       input.append(nama);
       input.append(gender);
       input.append(alamat);
       input.append(telp);
       input.append(email);
       input.append(tgl);
     
    }
   
    public void startApp(){
        if (display == null){
            display = Display.getDisplay(this);
            display.setCurrent(input);
        }
    }
   
    public void pauseApp(){
       
    }
   
    public void destroyApp(boolean unconditional){
       
    }

    public void commandAction(Command c, Displayable d) {
        if(c == view){
            input.deleteAll();
           
            text = new StringItem("", "nama : "+nama.getString()+"\n"
            +"gender : "+gender.getString(gender.getSelectedIndex())+"\n"
            +"alamat : "+alamat.getString()+"\n"
            +"nomer : "+telp.getString()+"\n"
            +"email : "+email.getString()+"\n"
            +"BDay : "+tgl.getDate());
           
            warning = new Alert("Alert Warning","harus terisi semua",null,AlertType.WARNING);
            warning.setTimeout(Alert.FOREVER);
            display.setCurrent(warning, d);
           
            input.append(text);
            input.removeCommand(view);
            input.addCommand(exit);
        }
       
        if (c == exit){
            destroyApp(true);
            notifyDestroyed();
        }
    }
   
}


dan berikut ini hasil dari running di emulator




Using TextField on Java MIDlet


textfield adalah tempat dimana pengguna dapat memasukkan input
berikut ini script jika anda ingin mencoba beberapa textfield yang ada,

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class formexpert extends MIDlet implements CommandListener {
    Display display;
    Form textForm;
    Command exitCommand = new Command("Exit", Command.EXIT,1);
    DateField dateonly,timeonly,datetime;
    Ticker ticker = new Ticker(
            "JENI - Java Education Network Type");
    public formexpert(){
        textForm =new Form("TextField Type");
        textForm.addCommand(exitCommand);
        textForm.setCommandListener(this);
        TextField ANY = new TextField("ANY", "", 64, TextField.ANY);
        TextField EMAILADDR = new TextField("EMAILADDR", "", 64, TextField.EMAILADDR);
        TextField NUMERIC = new TextField("NUMERIC", "", 64, TextField.NUMERIC);
        TextField PHONENUMBER = new TextField("PHONENUMBER", "", 64, TextField.PHONENUMBER);
        TextField URL = new TextField("URL", "", 64, TextField.URL);
        TextField DECIMAL = new TextField("DECIMAL", "", 64, TextField.DECIMAL);
        textForm.append(ANY);
        textForm.append(EMAILADDR);
        textForm.append(NUMERIC);
        textForm.append(PHONENUMBER);
        textForm.append(URL);
        textForm.append(DECIMAL);
        textForm.setTicker(ticker);
    }
    public void startApp() {
        if (display == null){
            display = Display.getDisplay(this);
            display.setCurrent(textForm);
        }
    }
    public void pauseApp() {
    }
    public void destroyApp(boolean unconditional) {
    }
    public void commandAction(Command c, Displayable d){
        if (c == exitCommand){
            destroyApp(true);
            notifyDestroyed();
        }
    }
}

dan berikut ini hasil dari running di emulator


Membuat aplikasi mobile dengan MIDlet


Langka-langkah
11. Buka netbeans -> file -> new project -> pilih kategori java ME dan project mobile aplication
12. Kemudian Next dan isikan pada project name nama project anda, misal hallo
13. Kita Next lagi dan pilih device configuration pilih CLDC-1.1 dan device profile MIDP-2.1
14. Kemudian ketikkan scrip berikut


 import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public  class hello extends MIDlet implements CommandListener {
Display display;
Command exitCommand = new Command ("Exit", Command.EXIT,1);
Alert helloAlert;
public hello(){
    helloAlert = new Alert("Hello MIDlet","Hello, world!",null,AlertType.INFO);
    helloAlert.setTimeout(Alert.FOREVER);
    helloAlert.addCommand(exitCommand);
    helloAlert.setCommandListener(this);
}
public void startApp(){
    if (display==null){
        display = Display.getDisplay(this);
    }
    display.setCurrent(helloAlert);
}
public void pauseApp(){
   
}
public void destroyApp(boolean unconditional){
   
}
public void commandAction(Command c, Displayable d){
    if (c == exitCommand){
        destroyApp(true);
        notifyDestroyed();
    }
}
}

15. Hasil setelah di run pada emulator

Wily Cahyadi. Diberdayakan oleh Blogger.