Skip to main content

adding

2 replies [Last post]
knownothing
Offline
Joined: 2010-05-09
Points: 0

what is the essiest way to make a TextField with are a
calculator (only adding and 1 number, if you press on 5 it
show 5 then 6 it show 11 then 3 it show 14 aso)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jaywayjohan
Offline
Joined: 2008-06-18
Points: 0

Set the ItemStateListener on the Form which the TextField is placed.

Look at this documentation for more information:

http://java.sun.com/javame/reference/apis/jsr118/

Regards
Johan

knownothing
Offline
Joined: 2010-05-09
Points: 0

This code work perfect with Suns emulator but not in Nokia mobile Why ?

int oldnumber =0;

public void itemStateChanged(Item item){
if (item instanceof TextField){
TextField text=(TextField)item;
int newNumber=oldNumber+Integer.parseInt(text.getString().substring(text.getString().length()-1,text.getString().length()));
oldnumber=newnumber;
text.setString(""+newNumber);