Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaME input text boxes problmes

Status
Not open for further replies.

OMGNinja

Programmer
Apr 1, 2010
9
US
ok so I want to get input from the user for ending and begining mileage of a car and how much gas that is used during the travle.I got the input boxes set up that works fine but when I try to convert them to ints it does not what I am I doing wrong here?
Code:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.TextField;



public class Gas extends MIDlet  implements CommandListener {

  
    //gas mileage = (em - bm)/ gas;

TextField gas; //gas in gallons
TextField bm;  //begingin mileage
TextField em;  //ending mileage
int result; // //gas mileage = (em - bm)/ gas;

    private Form form;
    private Command quit;
    private Command OKCmd;


public Gas(){
    gas = new TextField("Gas in Gallons:", "", 10, TextField.ANY);
    bm = new TextField("Begining Mileage :", "", 10, TextField.ANY);
    em = new TextField("Ending Mileage :", "", 10, TextField.ANY);

      form = new Form("Gas Milages");
     
      form.setCommandListener(this);
      quit = new Command("Quit", Command.SCREEN, 1);
      form.addCommand(quit);
      OKCmd = new Command("OK", Command.SCREEN, 1);
      form.addCommand(OKCmd);
      form.append(gas);
      form.append(bm);
      form.append(em);
      


   }
protected void startApp() throws MIDletStateChangeException{

      Display.getDisplay(this).setCurrent(form);
   }


   protected void pauseApp(){
   }


   protected void destroyApp(boolean unconditional)
           throws MIDletStateChangeException{
   }


   // Handle Events generated by Commands
   public void commandAction(Command command, Displayable displayable){
try{
       if (command == OKCmd){
       int gInput = Integer.parseInt(gas.getString());
       int bMInput = Integer.parseInt(bm.getString());
       int eMInput = Integer.parseInt(em.getString());
       }
}catch(NumberFormatException e){}
        //gas mileage = (em - bm)/ gas;
       // result = (em - bm) / gas;
       try
      {
         if (command == quit)
         {
            destroyApp(true);
            notifyDestroyed();
         }
      }

      catch (MIDletStateChangeException me){
      }
   }
}
 
Ok I got it working, i feel kinda stupid this look like a noob mistake, but hey I am one so :)
but here is how to fix this problem

Code:
int gInput = Integer.parseInt(gas.getString());
       int bMInput = Integer.parseInt(bm.getString());
       int eMInput = Integer.parseInt(em.getString());
        result = (eMInput -bMInput) / gInput ;

Now I have gotten this part does any one know how to get print out the result to the screen?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top