Pengikut

Rabu, 29 April 2009

FirstChoiceGroup

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

public class FirstChoiceGroup extends MIDlet implements CommandListener {
 Display display;
 FirstChoiceGroupForm form; 
 List list;
 Command cmExit;

 public FirstChoiceGroup() {
  display = Display.getDisplay(this);
 }

 public void startApp() {
  list = new List("First ChoiceGroup", List.IMPLICIT);
  list.append("EXCLUSIVE", null);
  list.append("MULTIPLE", null);
  list.append("POPUP", null);
  list.append("TEXT WRAP OFF", null);
  list.append("TEXT WRAP ON", null);
  
  cmExit = new Command("Keluar", Command.EXIT, 1);

  list.addCommand(cmExit);
  list.setCommandListener(this);
  display.setCurrent(list);
 }

 public void pauseApp() {
 }

 public void destroyApp(boolean unconditional) {
 }

 public void exitMIDlet() {
  destroyApp(false);
  notifyDestroyed();
 }

 public void commandAction(Command c, Displayable s){
  if (c == List.SELECT_COMMAND){
  switch (list.getSelectedIndex()){
  case 0:  
  form = new FirstChoiceGroupForm(this, display, 0); 
  display.setCurrent(form);
  break;
  case 1:
  form = new FirstChoiceGroupForm(this, display, 1); 
  display.setCurrent(form);
  break;
  case 2:
  form = new FirstChoiceGroupForm(this, display, 2); 
  display.setCurrent(form);
  break;
  case 3:
  form = new FirstChoiceGroupForm(this, display, 3); 
  display.setCurrent(form);
  break;
  case 4:
  form = new FirstChoiceGroupForm(this, display, 4); 
  display.setCurrent(form);
  break;
  }
  }else if(c == cmExit){
  exitMIDlet();
  }
 }
};

FirstChoiceGroupForm.java
import javax.microedition.lcdui.*;

class FirstChoiceGroupForm
extends Form
implements CommandListener
{
 private Display display; 
 private Command cmBack, cmExit; 
 private FirstChoiceGroup midlet;
 private ChoiceGroup cgEx, cgMu, cgPo, cgTf, cgTn;

 public FirstChoiceGroupForm(FirstChoiceGroup midlet, Display display, int choice) {
  super("First ChoiceGroup");
  this.display = display;
  this.midlet = midlet;

  switch (choice){
  case 0:  
  cgEx = new ChoiceGroup("EXCLUSIVE", Choice.EXCLUSIVE);
  cgEx.append("string 1", null);
  cgEx.append("string 2", null);
  cgEx.append("string 3", null);
  append(cgEx);
  break;
  case 1:  
  cgMu = new ChoiceGroup("MULTIPLE", Choice.MULTIPLE);
  cgMu.append("string 1", null);
  cgMu.append("string 2", null);
  cgMu.append("string 3", null);
  append(cgMu);
  break;
  case 2:  
  cgPo = new ChoiceGroup("POPUP", Choice.POPUP);
  cgPo.append("string 1", null);
  cgPo.append("string 2", null);
  cgPo.append("string 3", null);
  append(cgPo);
  break;
  case 3:  
  cgTf = new ChoiceGroup("TEXT WRAP OFF", Choice.TEXT_WRAP_OFF);
  cgTf.append("text wrap off striiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiing 1", null);
  cgTf.append("text wrap off striiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiing 2", null);
  cgTf.append("text wrap off striiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiing 3", null);
  append(cgTf);
  break;
  case 4:  
  cgTn = new ChoiceGroup("TEXT WRAP ON", Choice.TEXT_WRAP_ON);
  cgTn.append("text wrap on striiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiing 1", null);
  cgTn.append("text wrap on striiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiing 2", null);
  cgTn.append("text wrap on striiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiing 3", null);
  append(cgTn);
  break;
  }

  cmBack = new Command("Kembali", Command.BACK, 1);
  addCommand(cmBack);  

  cmExit = new Command("Keluar", Command.EXIT, 1);
  addCommand(cmExit);

  setCommandListener(this);
 }

 public void commandAction(Command c, Displayable s){
  if (c == cmBack) {
  display.setCurrent(midlet.list);
  }else if (c == cmExit) {
  midlet.exitMIDlet();
  }
 }
}

Simple Alert with Image and Default Warning Sound

FirstAlert.java

import javax.microedition.midlet.*;

import javax.microedition.lcdui.*;

public class FirstAlert extends MIDlet implements CommandListener{
 Display display;
 List list;
 Image img;
 Alert alAl, alCo, alEr, alIn, alWa;
 Command cmExit;

 public FirstAlert() {
  display = Display.getDisplay(this);
  try {
  img = Image.createImage("/img.png");
  } catch (java.io.IOException e) {
  }
  cmExit = new Command("Exit", Command.EXIT, 1);
  list = new List("First Alert", List.IMPLICIT);
  list.append("ALARM", img);
  list.append("CONFIRMATION", img);
  list.append("ERROR", img);
  list.append("INFO", img);
  list.append("WARNING", img);
  list.addCommand(cmExit);
  list.setCommandListener(this);
  display.setCurrent(list);

  alAl = new Alert("ALARM", "Alert ALARM", null, AlertType.ALARM);
  alAl.setTimeout(Alert.FOREVER);

  alCo = new Alert("CONFIRMATION", "Alert CONFIRMATION", null, AlertType.CONFIRMATION);
  alCo.setTimeout(Alert.FOREVER);

  alEr = new Alert("ERROR", "Alert ERROR", null, AlertType.ERROR);
  alEr.setTimeout(Alert.FOREVER);

  alIn = new Alert("INFO", "Alert INFO", null, AlertType.INFO);
  alIn.setTimeout(Alert.FOREVER);

  alWa = new Alert("WARNING", "Alert WARNING", null, AlertType.WARNING);
  alWa.setTimeout(Alert.FOREVER);
 }

 public void startApp() {
 }

 public void pauseApp() {
 }

 public void destroyApp(boolean unconditional) {
 }

 public void commandAction(Command c, Displayable s){
  if (c == List.SELECT_COMMAND){
  switch (list.getSelectedIndex()){
  case 0:
  display.setCurrent(alAl);
  break;
  case 1:
  display.setCurrent(alCo, list);
  break;
  case 2:
  display.setCurrent(alEr);
  break;
  case 3:
  display.setCurrent(alIn, list);
  break;
  case 4:
  display.setCurrent(alWa);
  break;
  }
  }else if(c == cmExit){
  exitMIDlet();
  }
 }

 public void exitMIDlet() {
  destroyApp(false);
  notifyDestroyed();
 }
};



This project requires an image with the name "img.png" with size 15 x 15 pixels

 

© Copyright by See Complete Code | Template by BloggerTemplates | Blog vio at Blog-HowToTricks