/* * FormDemo.java * * Created on 13 ??????? 2546, 16:38 ?. */ import javax.microedition.midlet.*; import javax.microedition.lcdui.*; /** * An example MIDlet with simple "Hello" text and an Exit command. * Refer to the startApp, pauseApp, and destroyApp * methods so see how each handles the requested transition. * * @author sup98 * @version */ public class FormDemo extends MIDlet implements CommandListener, ItemStateListener { private Command exitCommand, okCommand, backCommand; private Display display; // The display for this MIDlet private List menu; private TextField tf1, tf2; private Form fr1, fr2, fr3; public FormDemo() { display = Display.getDisplay(this); exitCommand = new Command("Exit", Command.SCREEN, 1); backCommand = new Command("Back", Command.SCREEN, 2); okCommand = new Command("OK", Command.SCREEN,2); } /** * Start up the Hello MIDlet by creating the TextBox and associating * the exit command and listener. */ public void startApp() { menu = new List("Selection", List.IMPLICIT); menu.append("TextField",null); menu.append("Date",null); menu.append("Gauge",null); menu.addCommand(exitCommand); menu.setCommandListener(this); fr1 = new Form("Enter name"); fr1.append("First Name"); tf1 = new TextField("", "", 15, TextField.ANY); fr1.append(tf1); fr1.append("Last Name"); tf2 = new TextField("", "", 15, TextField.ANY); fr1.append(tf2); fr1.addCommand(backCommand); fr1.setCommandListener(this); fr2 = new Form("Change Date"); java.util.Date now = new java.util.Date(); DateField dateItem = new DateField("Today's date:", DateField.DATE); dateItem.setDate(now); fr2.append(dateItem); fr2.addCommand(backCommand); fr2.addCommand(okCommand); fr2.setItemStateListener(this); fr3 = new Form("Gauge Demo"); Gauge g = new Gauge("Level", true, 10, 0); fr3.append(g); fr3.addCommand(backCommand); fr3.setCommandListener(this); display.setCurrent(menu); } /** * Pause is a no-op since there are no background activities or * record stores that need to be closed. */ public void pauseApp() { } /** * Destroy must cleanup everything not handled by the garbage collector. * In this case there is nothing to cleanup. */ public void destroyApp(boolean unconditional) { } /* * Respond to commands, including exit * On the exit command, cleanup and notify that the MIDlet has been destroyed. */ public void commandAction(Command c, Displayable s) { if (c == exitCommand) { destroyApp(false); notifyDestroyed(); } else if (c == backCommand){ display.setCurrent(menu); } else if ((c == List.SELECT_COMMAND)&&(s == menu)){ switch (((List)menu).getSelectedIndex()){ case 0: display.setCurrent(fr1); break; case 1: display.setCurrent(fr2); break; case 2: display.setCurrent(fr3); break; } } } public void itemStateChanged(Item item) { java.util.Calendar cal = java.util.Calendar.getInstance(java.util.TimeZone.getDefault()); cal.setTime(((DateField) item).getDate()); } }