/* * flightTime.java * * Created on 15 February 2007, 11:09 */ package flight.org.uk; import java.util.Date; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; /** * * @author William * @version */ public class flightTime extends MIDlet implements CommandListener{ //define form private Form flightForm; private Form answerForm; //define stringItems StringItem flightFormTitle; StringItem flightFormDetails; StringItem answer; //define Datefields DateField departureTime; DateField ariavlTime; //Define commands Command calcCmd; Command extCmd; //others long calcAnswer; public Form setupFlightForm(){ //create items //create form flightForm = new Form("Flight Form"); //create string items flightFormTitle = new StringItem(null, "Flight arivial Calculation times"); flightFormDetails = new StringItem(null,"Please enter the departure time and arivial time, Then press the calculate button"); answer = new StringItem(null, "Answer :" + this.calcAnswer); //create datefeilds departureTime = new DateField(null, DateField.TIME); ariavlTime = new DateField(null, DateField.TIME); //create commands calcCmd = new Command("Calculate", Command.OK,0); extCmd = new Command("Exit", Command.EXIT,0); //set listener flightForm.setCommandListener(this); flightForm.append(flightFormTitle); flightForm.append(flightFormDetails); flightForm.append(departureTime); flightForm.append(ariavlTime); flightForm.append(answer); flightForm.addCommand(extCmd); flightForm.addCommand(calcCmd); //return form return flightForm; } /** *commandAction */ public void commandAction(Command c, Displayable s){ if (s == flightForm){ if(c.getCommandType() == Command.EXIT){ notifyDestroyed(); } if (s == flightForm){ if(c.getCommandType() == Command.OK){ calcAnswer = ariavlTime.getDate().getTime() - departureTime.getDate().getTime() ; } } } } public void startApp() { //create forms flightForm = this.setupFlightForm(); //set display Display.getDisplay(this).setCurrent(flightForm); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } }