import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class Kalkulaator2 extends MIDlet implements CommandListener{ TextField tf1=new TextField("Esimene arv", "", 5, TextField.NUMERIC); TextField tf2=new TextField("Teine arv", "", 5, TextField.NUMERIC); StringItem vastus=new StringItem("Vastus", ""); String[] tehted={"+", "-", "*", "/"}; List nimistu=new List("Tehte valik", List.EXCLUSIVE, tehted, null); StringItem silt=new StringItem("Tehe", "+"); Command c1=new Command("Arvuta", Command.SCREEN, 1); Command c2=new Command("Välju", Command.EXIT, 1); Command c3=new Command("Vali tehe", Command.SCREEN, 1); Command c4=new Command("Tehe valitud", Command.SCREEN, 1); Form f=new Form("Arvutaja"); public Kalkulaator2(){ f.append(tf1); f.append(silt); f.append(tf2); f.append(vastus); f.addCommand(c1); f.addCommand(c2); f.addCommand(c3); nimistu.addCommand(c4); f.setCommandListener(this); nimistu.setCommandListener(this); Display.getDisplay(this).setCurrent(f); } protected void startApp( ) throws MIDletStateChangeException{} protected void pauseApp( ){} protected void destroyApp( boolean p1 ) throws MIDletStateChangeException{ } void arvuta(){ int arv1=Integer.parseInt(tf1.getString()); int arv2=Integer.parseInt(tf2.getString()); String tulemus=""; if(silt.getText().equals("+")){tulemus=String.valueOf(arv1+arv2);} if(silt.getText().equals("-")){tulemus=String.valueOf(arv1-arv2);} if(silt.getText().equals("*")){tulemus=String.valueOf(arv1*arv2);} if(silt.getText().equals("/")){tulemus=String.valueOf(arv1/arv2);} vastus.setText(tulemus); } public void commandAction( Command p1, Displayable p2 ){ if (p1==c1){ arvuta(); } if(p1==c2){ notifyDestroyed(); } if(p1==c3){ Display.getDisplay(this).setCurrent(nimistu); } if(p1==c4){ silt.setText(nimistu.getString(nimistu.getSelectedIndex())); Display.getDisplay(this).setCurrent(f); } } }