/* * flightTime.java * * Created on 15 February 2007, 11:09 */ package flight.org.uk; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; /** * * @author William * @version */ public class flightTime extends MIDlet implements CommandListener{ //define forms private Form welcomeForm; private Form flightForm; private Form answerForm; //define stringItems StringItem welcomeMessage; StringItem flightFormTitle; StringItem flightFormDetails; StringItem answerFormTitle; StringItem answerFormAnswer; //define text fields DateField DepartureTime; DateField arriavlTime; //Define commands Command nxtCmd; Command bckCmd; Command extCmd; public Form setupWelcomeForm(){ //create items welcomeForm = new Form("Welcome Form"); welcomeMessage = new StringItem(" ", "Welcome To The Flight Calculaton Mobile Application \n \n Please press next"); nxtCmd = new Command("Next", Command.OK, 0); //set listner(s) welcomeForm.setCommandListener(this); //add items to form welcomeForm.append(welcomeMessage); welcomeForm.addCommand(nxtCmd); //return form return welcomeForm; } public Form setupFlightForm(){ //create items flightForm = new Form("Flight Form"); flightFormTitle = new StringItem("Flight Form", null); flightFormDetails = new StringItem("", " Please enter your details below"); DateField DepartureTime = new DateField("Depart ", 2, null); DateField arriavlTime = new DateField("Arival ", 2, null); long answer1 = arriavlTime.getDate().getTime() - DepartureTime.getDate().getTime() ; StringItem answer = new StringItem("Answer :", " " + answer1); nxtCmd = new Command("Calculate", Command.OK, 0); bckCmd = new Command("Back", Command.BACK, 0); //set listner(s) flightForm.setCommandListener(this); //add items to form flightForm.append(flightFormTitle); flightForm.append(flightFormDetails); flightForm.append(DepartureTime); flightForm.append(arriavlTime); flightForm.append(answer); flightForm.addCommand(nxtCmd); flightForm.addCommand(bckCmd); //return form return flightForm; } /** *commandAction */ public void commandAction(Command c, Displayable s){ if (s == welcomeForm){ if(c.getCommandType() == Command.OK){ Display.getDisplay(this).setCurrent(flightForm); } } else if (s == flightForm){ if(c.getCommandType() == Command.BACK){ Display.getDisplay(this).setCurrent(welcomeForm); } if (s == flightForm){ if(c.getCommandType() == Command.OK){ Display.getDisplay(this).setCurrent(answerForm); } } } } public void startApp() { welcomeForm = this.setupWelcomeForm(); flightForm = this.setupFlightForm(); Display.getDisplay(this).setCurrent(welcomeForm); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } }