我正在使用Java ME制作计算器。我很难显示输出。
这是我的代码:
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);
}
答案 0 :(得分:0)
尝试这样的事情:
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
}
}
或者请说明你想把结果放在哪里