Posting lagi nih, hehe. Kali ini saya mau share hasil dari tugas yaitu Membuat FORM. Ikuti sintaks di bawah ini :



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

public class textfield extends MIDlet implements CommandListener {
 
    Display tampil;
    Form FormInput, FormHasil;
    TextField name, address, contact, email;
    Command cmdOK, cmdExit,cmdBack;
    ChoiceGroup gender;
    Ticker ticker;
    DateField date;
    Alert alert;
     
    public textfield() {
        cmdOK = new Command("SIMPAN", Command.OK, 1);
        cmdBack = new Command("KEMBALI", Command.BACK, 1);
        cmdExit = new Command("KELUAR", Command.EXIT, 1);    
     
        FormInput = new Form("Data Diri");
     
        name    = new TextField  ("Nama          : ", null, 50, TextField.ANY);
        gender  = new ChoiceGroup("Jenis Kelamin : ", Choice.POPUP);
        gender.append("Laki-Laki", null);
        gender.append("Perempuan", null);
        address = new TextField  ("Alamat        : ", null, 50, TextField.ANY);
        contact = new TextField  ("Telepon       : ", null, 20, TextField.PHONENUMBER);
        email   = new TextField  ("E-mail        : ", null, 20, TextField.EMAILADDR);
        date    = new DateField  ("Tanggal lahir : ", DateField.DATE);
     
        ticker = new Ticker("5302410103 - AHMAD SAIFUL AMRI");
        alert = new Alert("ERROR", "Data yang anda masukkan belum lengkap", null, AlertType.ERROR);

        FormInput.append(name);
        FormInput.append(gender);
        FormInput.append(address);
        FormInput.append(contact);
        FormInput.append(email);
        FormInput.append(date);
        FormInput.addCommand(cmdOK);
        FormInput.addCommand(cmdExit);
        FormInput.setTicker(ticker);
        FormInput.setCommandListener(this);
    }
 
    protected void destroyApp(boolean arg0) {
        notifyDestroyed();
    }
 
    protected void pauseApp() {
        // TODO Auto-generated method stub
    }

    protected void startApp() {
        if (tampil == null){
            tampil = Display.getDisplay(this);
            tampil.setCurrent(FormInput);
        }
    }

    public void commandAction(Command c, Displayable d) {

                if(c == cmdOK){                                      
                        if (name.getString().equals("") || address.getString().equals("")
                                || contact.getString().equals("") || email.getString().equals("")){
                            tampil.setCurrent(alert);
                            alert.setTimeout(Alert.FOREVER);
                            alert.addCommand(cmdBack);
                        }
                        else {
                            FormHasil = new Form("Biodata Anda: ");
                            FormHasil.deleteAll();

                            FormHasil.append ("Nama          : " + name.getString()
                                     + '\n'+'\n' + "Jenis Kelamin : " + gender.getString(gender.getSelectedIndex())
                                     + '\n'+'\n' + "Alamat        : " + address.getString()
                                     + '\n'+'\n' + "Contact       : " + contact.getString()
                                     + '\n'+'\n' + "Email         : " + email.getString()
                                     + '\n'+'\n' + "Tanggal Lahir : " + date.getDate());
                         
                            FormHasil.addCommand(cmdBack);
                            FormHasil.addCommand(cmdExit);
                            FormHasil.setCommandListener(this);
                            tampil.setCurrent(FormHasil);
                        }
                 
                }else if(c==cmdBack){
                    Display.getDisplay(this).setCurrent(FormInput);
                }else if(c==cmdExit){
                    destroyApp(true);
                }
            }
    }




Hasil Printscreenya :





Terima kasih, jika masih ada kesalahan saya pasti akan perbaiki :)

Categories:

One Response so far.

  1. Anonim says:

    manaaaa bosss?

Leave a Reply