Advertisers

Kirimkan Donasi Anda
$

JSS Tripler Dahsyat

Senin, 19 Maret 2012

Membuat Form baru dan Text Box pada Java Netbeans IDE 7.1 dengan java J2ME

Membuat Form baru dan Text Box pada Java Netbeans IDE 7.1

 1. Buka Netbeans IDE 7.1
 2. klik new project.
 3. Pilih Java ME lalu pilih Project Mobile Application kemudian tekan Next.
 4 Copy source code berikut.

package pkgprak2;

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

/**
 * @author FAIRUS ANWAR
 */
public class Prak2Midlet extends MIDlet implements CommandListener {
   
    private FormInput frmInput;
    private FormShow1 frmShow1;
    private FormShow2 frmShow2;
   
    private Command cmShow1, cmShow2, cmBack, cmExit;

    public void startApp() {
        if (frmInput == null)
            frmInput = new FormInput();
        if (frmShow1 == null)
            frmShow1 = new FormShow1();
        if (frmShow2 == null)
            frmShow2 = new FormShow2();
       
        cmShow1 = new Command("Tampilan 1", Command.OK, 0 );
        cmShow2 = new Command("Tampilan 2", Command.OK, 1 );
        cmBack = new Command("Kembali", Command.BACK, 0 );
        cmExit = new Command("Keluar", Command.EXIT, 0 );
       
        frmInput.addCommand(cmShow1);
        frmInput.addCommand(cmShow2);
        frmInput.addCommand(cmExit);
       
        frmShow1.addCommand(cmBack);
        frmShow2.addCommand(cmBack);
       
        frmInput.setCommandListener(this);
        frmShow1.setCommandListener(this);
        frmShow2.setCommandListener(this);
       
        Display.getDisplay(this).setCurrent(frmInput);
    }   
    public void pauseApp() {
    }   
    public void destroyApp(boolean unconditional) {
    }
    public void commandAction(Command c, Displayable d) {       
        if (d == frmInput) {
            if (c == cmExit) {
                destroyApp(true);
                notifyDestroyed();
            }           
            if (c == cmShow1) {
                frmShow1.setNama(frmInput.getNama());
                frmShow1.setEmail(frmInput.getEmail());
                Display.getDisplay(this).setCurrent(frmShow1);
            }           
            if (c == cmShow2) {
                frmShow2.setTextBox(frmInput.getNama() + " " + frmInput.getEmail());
                Display.getDisplay(this).setCurrent(frmShow2);
            }                       
        }       
        if (d == frmShow1) {
            if ( c == cmBack) {
                Display.getDisplay(this).setCurrent(frmInput);
            }
        }       
        if (d == frmShow2) {
            if ( c == cmBack) {
                Display.getDisplay(this).setCurrent(frmInput);
            }         
        }
    }
}


Maka akan tampil Output seperti dibawah ini.

0 komentar:

Posting Komentar

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More