-1

I'm making a calculator using Java ME. I'm having a hard time displaying the output.

Here's my code:

  public void menuadd(){

  vswitch=2;
  Form formadd = new Form("addition");
  add1 = new TextField("1st Number:", "", 30, TextField.DECIMAL);

  add2 = new TextField("2nd Number:", "", 30, TextField.DECIMAL);
  disp = Display.getDisplay(this);
  cmdok = new Command("OK", Command.OK, 2);
  formadd.addCommand(cmdok);
  formadd.append(add1);
  formadd.append(add2);   
  formadd.setCommandListener(this);
  disp.setCurrent(formadd);
}
Ahmad
  • 12,336
  • 6
  • 48
  • 88
drayl
  • 261
  • 2
  • 8
  • 21
  • 5
    Instead of saying "I have a problem" try to get more specific help by pointing out what sort of problem you are facing and what is wrong with your output. – Milad Naseri Jul 21 '12 at 03:57
  • code snippet you posted here looks OK: should most likely display fine – gnat Jul 21 '12 at 09:09

1 Answers1

0

try something like this:

public void commandAction(Command c,Displayable dy)
{
if(c.equals(cmdok))
{
int num1=Integer.parseInt(add1.getString());
int num2=Integer.parseInt(add2.getString());
int result=num1+num2;
formadd.append(result+""); // +"" required to convert Integer back to String
}
}

or describe please where do you want to put the result

Alexey
  • 63
  • 1
  • 8