Tuesday, October 2, 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.");
    }
}

No comments:

Post a Comment