Senin, 01 Oktober 2012

LAB ACTIVITY HIGH LEVEL USER INTERFACE


PERCOBAAN 1 PENGGUNAAN ALERT

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

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

/**
 * @author pathek$
 */
public class AlertMidlet extends MIDlet implements CommandListener {
    Display display;
     Form mainForm;
     Command exitCommand = new Command("Exit", Command.EXIT, 0);
     Command okCommand = new Command("Ok", Command.OK, 0);
     Gauge gauge = new Gauge (null, false, 5, 0);
     Command[] commands = {
          new Command("Alarm", Command.OK, 0),
          new Command("Confirmation", Command.OK, 0),
          new Command("Info", Command.OK, 0),
          new Command("Warning", Command.OK, 0),
          new Command("Error", Command.OK, 0),
          new Command("Modal", Command.OK, 0)
     };
    

     Alert[] alerts = {
          new Alert("Alarm Alert", "Example of an Alarm type of Alert",
               null, AlertType.ALARM),
          new Alert("Confirmation Alert", "Example of an CONFIRMATION type of Alert",
               null, AlertType.CONFIRMATION),
          new Alert("Info Alert", "Example of an INFO type of Alert",
               null, AlertType.INFO),
          new Alert("Warning Alert", "Example of an WARNING type of Alert, w/ gauge indicator",
               null, AlertType.WARNING),
          new Alert("Error Alert", "Example of an ERROR type of Alert, w/ an 'OK' Command",
               null, AlertType.ERROR),
          new Alert("Modal Alert", "Example of an modal Alert: timeout = FOREVER",
               null, AlertType.ERROR),
     };
    
      public AlertMidlet() {
          mainForm = new Form("JEDI: Alert Example");
          mainForm.addCommand(exitCommand);
          for (int i=0; i<commands.length; i++) {
               mainForm.addCommand(commands[i]);
          }
         
          mainForm.setCommandListener(this);
          //Menambah sebuah gauge dan menge-set timeout (milliseconds)
          alerts[3].setIndicator(gauge);
          alerts[3].setTimeout(5000);
          //Menambah sebuah command untuk Alert
          alerts[4].addCommand(okCommand);
          //Menge-set alert
          alerts[5].setTimeout(Alert.FOREVER);
     }
         

    public void startApp() {
        if (display == null) {
               display = Display.getDisplay(this);
               display.setCurrent(mainForm);
          }
    }
   
    public void pauseApp() {
    }
   
    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable d) {
        //throw new UnsupportedOperationException("Not supported yet.");
        if (c == exitCommand) {
               destroyApp(true);
               notifyDestroyed(); //Exit
          }
          for (int i=0; i<commands.length; i++) {
               if (c==commands[i]) {
                    display.setCurrent(alerts[i]);
               } 
          }
    }
}




PERCOBAAN 2 PENGGUNAAN LIST

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

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

/**
 * @author pathek$
 */
public class ListMidlet extends MIDlet implements CommandListener {
    Display display;
     List list;
     Command exitCommand = new Command("Exit", Command.EXIT, 1);
     Command newCommand = new Command("New Item", Command.OK, 1);
     Command renameCommand = new Command("Rename Item", Command.OK, 1);
     Command deleteCommand = new Command("Delete Item", Command.OK, 1);
     Ticker ticker = new Ticker (
          "JEDI - JAVA Education and Development Initiative");
    
      public ListMidlet() {
          list = new List("JEDI: List Example", List.IMPLICIT);
          list.append("List Item #1", null);
          list.append("List Item #2", null);
          list.append("List Item #3", null);
          list.setTicker(ticker);
          list.addCommand(exitCommand);
          list.addCommand(newCommand);
          list.addCommand(renameCommand);
          list.addCommand(deleteCommand);
          list.setCommandListener(this);
     }

    public void startApp() {
         if (display == null) {
               display = Display.getDisplay(this);
               display.setCurrent(list);
          }
    }
   
    public void pauseApp() {
    }
   
    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable d) {
        if (c == exitCommand) {
               destroyApp(true);
               notifyDestroyed(); //Exit
          }
          if (c == List.SELECT_COMMAND) {
               int index = list.getSelectedIndex();
               String currentItem = list.getString(index);
               // menjalankan suatu hal
          }
        throw new UnsupportedOperationException("Not supported yet.");
    }
}



PERCOBAAN 3 CHOICE GROUP

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

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

/**
 * @author pathek$
 */
public class ChoiceGrupMidlet extends MIDlet implements CommandListener {
    Display display;
     Form choiceForm;
     Command exitCommand = new Command("Exit", Command.EXIT, 1);
     Command newCommand = new Command("New Item", Command.OK, 1);
     ChoiceGroup choiceExclusive, choiceMultiple, choicePopup;
    
     public ChoiceGrupMidlet() {
          choiceForm = new Form("Choice Group Types");
          choiceForm.addCommand(exitCommand);
          choiceForm.setCommandListener(this);
          choiceExclusive = new ChoiceGroup("Exclusive", Choice.EXCLUSIVE);
          choiceExclusive.append("Male", null);
          choiceExclusive.append("Female", null);
          choiceForm.append(choiceExclusive);

          choiceMultiple = new ChoiceGroup("Multiple", Choice.MULTIPLE);
          choiceMultiple.append("Apple", null);
          choiceMultiple.append("Orange", null);
          choiceMultiple.append("Grapes", null);
          choiceForm.append(choiceMultiple);

          choicePopup = new ChoiceGroup("Popup", Choice.POPUP);
          choicePopup.append("Asia", null);
          choicePopup.append("Europe", null);
          choicePopup.append("Americas", null);
          choiceForm.append(choicePopup);
         
     }

    public void startApp() {
         if (display == null) {
               display = Display.getDisplay(this);
               display.setCurrent(choiceForm);
          }
    }
   
    public void pauseApp() {
    }
   
    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable d) {
        //throw new UnsupportedOperationException("Not supported yet.");
         if (c == exitCommand) {
               destroyApp(true);
               notifyDestroyed(); //Exit
          }
    }
}



PERCOBAAN 4 DATE FIELD

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

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

/**
 * @author pathek$
 */

public class DataFieldMidlet extends MIDlet implements CommandListener  {
    Display display;
    Form dateForm;
    Command exitCommand = new Command("Exit", Command.EXIT, 1);
    DateField dateonly, timeonly, datetime;
   
    public DataFieldMidlet() {
          dateForm = new Form("Date Field Modes");
          dateForm.addCommand(exitCommand);
          dateForm.setCommandListener(this);
          DateField dateonly = new DateField("Birthday (DATE)", DateField.DATE);
          DateField timeonly = new DateField("Set Alarm (TIME)", DateField.TIME);
          DateField datetime = new DateField("Departure (DATE_TIME)", DateField.DATE_TIME);
          dateForm.append(dateonly);
          dateForm.append(timeonly);
          dateForm.append(datetime);
     }

    public void startApp() {
        if (display == null) {
               display = Display.getDisplay(this);
               display.setCurrent(dateForm);
          }
    }
   
    public void pauseApp() {
    }
   
    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable d) {
        //throw new UnsupportedOperationException("Not supported yet.");
        if (c == exitCommand) {
               destroyApp(true);
               notifyDestroyed(); //Exit
          }
    }
}


   
PERCOBAAN 5 PENGGUNAAN STRINGITEM

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

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

/**
 * @author Pathek$
 */
public class HelloMidlet extends MIDlet implements CommandListener, ItemCommandListener {
      Display display;
      Form stringForm;
      Command exitCommand = new Command("Exit", Command.EXIT, 1);
      DateField dateonly, timeonly, datetime;

      public HelloMidlet(){
            stringForm = new Form("StringField Modes");
            stringForm.addCommand(exitCommand);
            stringForm.setCommandListener(this);
            StringItem plain = new StringItem("Plain", "Plain Text",
Item.PLAIN);
            StringItem hyperlink = new StringItem("Hyperlink",
"http://www.sun.com", Item.HYPERLINK);
            hyperlink.setDefaultCommand(new Command("Set", Command.ITEM, 0));
            hyperlink.setItemCommandListener(this);
            StringItem button = new StringItem("Button", "Click me",
Item.BUTTON);
            button.setDefaultCommand(new Command("Set", Command.ITEM, 0));
            button.setItemCommandListener(this);
            stringForm.append(plain);
            stringForm.append(hyperlink);
            stringForm.append(button);
      }

      public void startApp() {
            if (display == null) {
                  display = Display.getDisplay(this);
                  display.setCurrent(stringForm);
            }
      }
     
      public void pauseApp() {
      }

      public void destroyApp(boolean unconditional) {
      }

      public void commandAction(Command c, Displayable d) {
           
            if (c == exitCommand) {
                  destroyApp(true);
                  notifyDestroyed(); // Exit
            }
      }
      public void commandAction(Command c, Item item) {
            if(item.getLabel().equals("Button")) {
                  //kerjakan Sesuatu
            }
            if(item.getLabel().equals("Hyperlink")) {
                  //kerjakan Sesuatu
            }
      }
    }
                  

  
PERCOBAAN 6 PENGGUNAAN IMAGE

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

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

/**
 * @author pathek$
 */
public class ImageMidlet extends MIDlet implements CommandListener {
    Display display;
    Form imageForm;
    Command exitCommand = new Command("Exit", Command.EXIT, 1);
    DateField dateonly, timeonly, datetime;
    Ticker ticker = new Ticker (
          "JEDI - JAVA Education Network Indonesia");
   
   
    public ImageMidlet() {
        imageForm = new Form("Image Item");
        imageForm.addCommand(exitCommand);
        imageForm.setCommandListener(this);
        imageForm.setTicker(ticker);
        try {
            Image img = Image.createImage("/cah-bagus.jpg");
            ImageItem image = new ImageItem("PHOTOKU", img, Item.LAYOUT_CENTER, "photoku");
            imageForm.append(image);   
        } catch (Exception e ) {e.printStackTrace();}
    }

    public void startApp() {
        if (display == null) {
               display = Display.getDisplay(this);
               display.setCurrent(imageForm);
          }
    }
   
    public void pauseApp() {
    }
   
    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable d) {
        //throw new UnsupportedOperationException("Not supported yet.");
        if (c == exitCommand) {
               destroyApp(true);
               notifyDestroyed(); //Exit
          }
         
    }
}



PERCOBAAN 7 PENGGUNAAN TEXTFIELD


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

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

/**
 * @author pathek$
 */
public class TextFieldMidlet extends MIDlet implements CommandListener {
    Display display;
    Form textForm;
    Command exitCommand = new Command("Exit", Command.EXIT, 1);
    DateField dateonly, timeonly, datetime;
    Ticker ticker = new Ticker (
          "JEDI - JAVA Education Network Indonesia");
   
    public TextFieldMidlet() {
        textForm = new Form("TextField Types");
        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);
    }

    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) {
        //throw new UnsupportedOperationException("Not supported yet.");
         if (c == exitCommand) {
               destroyApp(true);
               notifyDestroyed(); //Exit
          }
    }
}

  

PERCOBAAN 8 PENGGUNAAN ITEMSTATELISTENER

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

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.Calendar;
import java.util.TimeZone;
import java.util.Date;

/**
 * @author pathek$
 */
public class ItemStateMidlet extends MIDlet implements CommandListener, ItemCommandListener {
    private Display display;
    private Form form;
    private final Command cmdKeluar = new Command("Exit", Command.EXIT, 1);
    private Calendar cal;
   
    public ItemStateMidlet() {
        display = Display.getDisplay(this);
        form = new Form("Demo ItemStateListener");
        cal = Calendar.getInstance(TimeZone.getDefault());
        form.addCommand(cmdKeluar);
        form.setCommandListener(this);
        Date now = new Date();
        DateField dateItem = new DateField("Hari ini tanggal: ", DateField.DATE);
        dateItem.setDate(now);
        form.append(dateItem);
        display.setCurrent(form);
        //form.setItemStateListener(this);
    }

    public void startApp() {
         if (display == null) {
               display = Display.getDisplay(this);
               display.setCurrent(form);
          }
    }
   
    public void pauseApp() {
    }
   
    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable d) {
        //throw new UnsupportedOperationException("Not supported yet.");
        if (c == cmdKeluar) {
               destroyApp(true);
               notifyDestroyed(); //Exit
          }
    }
   
    public void ItemStateChanged(Item item) {
        cal.setTime(((DateField)item).getDate());
        Alert alert = new Alert("Informai", null, null, AlertType.INFO);
        alert.setTimeout(3000);
        alert.setString("Tanggal telah berhasil diubah");
        display.setCurrent(alert, form);
    }

    public void commandAction(Command c, Item item) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}


Tidak ada komentar:

Posting Komentar