Monday, December 3, 2012

Menggunakan objek Form pada JAVA (J2ME)

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class DemoForm extends MIDlet
    implements CommandListener {
   
    private Display display;
    private Form form;
    private TextField tf;
   
    private Command cmdKeluar;
    private Command cmdOK;
   
    public DemoForm() {
        display = Display.getDisplay(this);
        cmdKeluar = new Command("Keluar", Command.EXIT, 1);
        cmdOK = new Command("OK", Command.OK, 1);
    }
       
    public void startApp() {
        form = new Form("Demo Form");
        tf = new TextField("Masukkan nomor telepon:", "",
                        15, TextField.PHONENUMBER);
        form.append((Item) tf);
        form.addCommand(cmdKeluar);
        form.addCommand(cmdOK);
        form.setCommandListener(this);
        display.setCurrent(form);
    }
   
    public void pauseApp() {
       
    }
   
    public void destroyApp(boolean unconditional) {
        notifyDestroyed();
    }
   
    public void commandAction(Command c, Displayable s) {
        if (c == cmdKeluar) {
            destroyApp(false);
        } else {
            Alert info = new Alert("Informasi");
            info.setType(AlertType.INFO);
            String teks = null;
            teks = tf.getString();
            info.setString("Nomor telepon: \"" +
teks + "\"");
            info.setTimeout(Alert.FOREVER);
            display.setCurrent(info, form);
        }
    }       
}

No comments:

Post a Comment