Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

focus problem!

 
Mateen Dar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi my j2me client contains twoi textfields. in which the user has to enter two strings. there is a menu whichs help the user to complete any of the two strings. so that when the user presses the ok button, the select text enters the textfield the the user was using when he pressed the help menu. how do i get to know which of the two textfields had the focus, when the menu was clicked.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way is to keep track of the field they are in with an instance vairable. So when you enter the field, you set that variable to some constant, then when you enter the other field you set it to another constant, then when the Command is clicked, then look at that instance variable to see the last field that they were in.

Kind of a hack.

Mark
 
Mateen Dar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is actually what i want.. but how do i know when a user has entered the field. thanks
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ItemStateListener

Have your form implement this interface which has the itemStateChanged method.

Then call

Form.setItemStateListener(ItemStateListener)

Method Summary
void itemStateChanged(Item item)
Called when internal state of an Item has been changed by the user.

In the itemStateChanged method check for each Item with item parameter and work that way.

Mark
 
Mateen Dar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks. will this work
int whichOne=0;
TextField temp=(Texfield)item;
if(temp.equals(firstTextField)
{
// the frist one got a focus
whichOne=1;
}

if(temp.equals(firstTextField)
{
// the second one got a focus
whichOne=2;
}


is this ok!
i also notised the textfield has a itemstatechanged.. what is this for
 
Mateen Dar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public void itemStateChanged (Item e)
{
if(e instanceof TextField)
{
TextField temp=(TextField)e;
d1.setString ("here");
if(temp.equals (b1))
{ which=1; }

if(temp.equals (c1))
{which=2; }
}
}
this code works only when the user edits the first or the second field, this event id not fired by moving the key between the two textfields. how can this be done. is there no FocusListener
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No there isn't a FocusListener. Remember they need to keep the amount of classes down to a minimun, so they figure the ItemStateListener is enough to cover all somthing or other.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic