Selasa, 22 Oktober 2013

Pertemuan 5

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

/**
 * @author user
 */
public class Utama extends MIDlet implements CommandListener{
    Display tampilan;
    Form frmLogin, frmGambar;
    TextField txtUsername, txtPassword;
    Command cmdLogin, cmdExit;

    Image imgContoh1, imgContoh2;
    Alert error1, error2, error3, error4;
    List lstMenu;

    public Utama(){
        tampilan = Display.getDisplay(this);
        frmLogin = new Form("LOGIN PAGE");
        frmGambar = new Form("TAMPILAN GAMBAR");
        txtUsername = new TextField("Username :", "",10,TextField.NUMERIC);
        txtPassword = new TextField("Password :", "",4,TextField.PASSWORD);
        cmdLogin = new Command("LOGIN",Command.ITEM,2);
        cmdExit = new Command("EXIT",Command.EXIT,2);

        try {
            imgContoh1 = Image.createImage("/persia.jpg");
            imgContoh2 = Image.createImage("/anggora.jpg");
        } catch (IOException ex) {
            ex.printStackTrace();
        }


        lstMenu = new List("TAMPILAN MENU", List.IMPLICIT);
        lstMenu.append("KE FORM LOGIN", null);
        lstMenu.append("KE TAMPILAN MENU 2", null);
        lstMenu.append("KE TAMPILAN MENU 3", null);
        lstMenu.setCommandListener(this);

        //loadingForm1();
        //loadingForm2();
    }
    public void startApp() {
        tampilan.setCurrent(lstMenu);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c,Displayable d){
        if (c == List.SELECT_COMMAND){
            switch(lstMenu.getSelectedIndex()){
                case 0 : tampilan.setCurrent(frmLogin); break;
                case 1 : tampilan.setCurrent(frmGambar);break;
                case 2 : notifyDestroyed(); break;
            }
        }

        if (d == frmLogin){
            if (c == cmdExit){
                tampilan.setCurrent(lstMenu);

            }
        }
    }
    public void loadingForm1(){
        frmLogin.append(txtUsername);
        frmLogin.append(txtPassword);
        frmLogin.addCommand(cmdLogin);
        frmLogin.addCommand(cmdExit);
        frmLogin.setCommandListener(this);

    }
    public void loadingForm2(){
        frmGambar.append(new ImageItem(null,imgContoh1,ImageItem.LAYOUT_CENTER,null));
        frmGambar.append(new ImageItem(null,imgContoh2,ImageItem.LAYOUT_BOTTOM,null));
        frmGambar.addCommand(cmdExit);
        frmGambar.setCommandListener(this);
   

    }
}

Selasa, 01 Oktober 2013

Pertemuan keempat


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.*;

/**
 * @author user
 */
public class Programkeempat extends MIDlet implements CommandListener{

    Display display;
   Form form;
   Form form2;
   TextField txtNama;
   TextField txtNPM;
   TextField txtKelas;
   TextField txtHobi;
   TextField txtCitacita;
   TextField txtAngkapertama;
   TextField txtAngkaKedua;

   Command cmdkeluar;
   Command cmdsimpan;



   public Programkeempat(){
       display = Display.getDisplay(this);

       form = new Form("Pengisian Data");
       form2 = new Form("");
      
       txtNama = new TextField("Nama", null, 10, TextField.ANY);
       txtNPM = new TextField("NPM", null, 25, TextField.NUMERIC);
       txtKelas = new TextField("Kelas", null, 10, TextField.ANY);
       txtHobi = new TextField("Hobi", null, 20, TextField.ANY);
       txtCitacita = new TextField("Cita-Cita", null, 30, TextField.ANY);
       txtAngkapertama = new TextField("Angkaperta", null, 25,TextField.ANY);
       txtAngkaKedua = new TextField("Angkakedua", null, 15, TextField.ANY);

       cmdkeluar = new Command("Keluar", Command.EXIT, 1);
       cmdsimpan = new Command("Simpan", Command.OK, 1);

       form.append(txtNama);
       form.append(txtNPM);
       form.append(txtKelas);
       form.append(txtHobi);
       form.append(txtCitacita);
       form.append(txtAngkapertama);
       form.append(txtAngkaKedua);
      

       form.addCommand(cmdkeluar);
       form.addCommand(cmdsimpan);

      
       form.setCommandListener(this);
       form2.setCommandListener(this);







   }

    public void startApp() {
        display.setCurrent(form);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable d) {
        if(c==cmdkeluar){

            destroyApp(false);
            this.notifyDestroyed();
        }
        else if(c==cmdsimpan){
            form2.append(txtNama.getString() +"\n");
            form2.append(txtNPM.getString() +"\n");
            form2.append(txtKelas.getString() +"\n");
            form2.append(txtHobi.getString() +"\n");
            form2.append(txtCitacita.getString() +"\n");
           
            int i = Integer.parseInt(txtAngkapertama.getString());
            int j = Integer.parseInt(txtAngkaKedua.getString());
            int jumlah = i + j;

            form2.append("Angka Pertama : " + i + "\n");
            form2.addCommand(cmdkeluar);
            display.setCurrent(form2);
        }
    }
}