this code gives addition of 2 numbers in j2me..but the code is not executing ..can u pls find out the error...??

import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class add1 extends MIDlet implements CommandListener { private Form f; private Display disp; private Command result,ok; private TextField t1,t2; public add1() { f=new Form("Addtion of two numbers"); // result=new Command("Result",Command.OK,1); ok=new Command("Ok",Command.OK,1); t1=new TextField("enter the first number",null,50,TextField.NUMERIC); t2=new TextField("enter the second number",null,50,TextField.NUMERIC); f.append(t1); f.append(t2); // f.addCommand(result); f.addCommand(ok); disp.getDisplay(this).setCurrent(f);

}
public void startApp() {
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

public void commandAction(Command command, Displayable displayable) {
    if(command.getCommandType()==command.OK)
    {
        Form f2=new Form("displaying result");
        String n=t1.getString();
        String cd=t2.getString();
        int n1=Integer.parseInt(n);
        int n2=Integer.parseInt(cd);
        int result=n1+n2;
        f2.append(String.valueOf(result));
        Command c3=new Command("back",Command.BACK,1);
        f2.addCommand(c3);
        f2.setCommandListener(this);
        disp.getDisplay(this).setCurrent(f2);

    }
}

}

View Answers









Related Tutorials/Questions & Answers:
Advertisements