aspose file tools*
The moose likes Java Micro Edition and the fly likes focus problem! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "focus problem!" Watch "focus problem!" New topic
Author

focus problem!

Mateen Dar
Ranch Hand

Joined: Jan 14, 2005
Posts: 55
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

Joined: Feb 05, 2001
Posts: 17250
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mateen Dar
Ranch Hand

Joined: Jan 14, 2005
Posts: 55
this is actually what i want.. but how do i know when a user has entered the field. thanks
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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

Joined: Jan 14, 2005
Posts: 55
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

Joined: Jan 14, 2005
Posts: 55
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

Joined: Feb 05, 2001
Posts: 17250
    
    6

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
 
Consider Paul's rocket mass heater.
 
subject: focus problem!