Skip to main content

Is it possible to give each component an ID which can get component?

6 replies [Last post]
ousys
Offline
Joined: 2008-05-14

Hello , is it possible to give each component an ID, and then I could do something like getTextFromID()....
in my code , I declared one textfield,
TextField tf;
and I do such things,
for(int i=0;i<=2;i++){
tf=new TextField()
form.addComponent(tf);
}
form.show();

and in Display , they can actually display 3 TextField.
But now I want to get the Text in each textfield , dunno how to implement , anybody can give my any idea?

Thank you!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ousys
Offline
Joined: 2008-05-14

Okay,Chen, nafs, thank you!

ousys
Offline
Joined: 2008-05-14

Thank you for your reply , I think if it is TextField , then I could do what you told me , use DataChangeListener, each time whatever textfield changed, just use tf.getText(),and insert the (data+ custom_id) into a String to keep all of the TextField data before it sends to the server side, then I think server side maybe also could get the different textfield data and identify them.
---------------------------------------------------------
But if there is 3 or more buttons on the TextField with the same declaration like Button btn, such as what I do to TextField, then is it also possible to sign different btn different actions?
------------------
(ps. Now I am doing a thing---by using LWUIT parse file, which sounds a little like a browser, so different btn need different action, such as link to a.jsp, or go to b.jsp, or do some functions, and server side can use a servlet to identify what button clicked and the server can do different things for what it receives ).
Looking forward for your reply, thank you! ^_^

nafs
Offline
Joined: 2008-06-10

"[i]..server side can use a servlet to identify what button clicked[/i].. "
This is not good design. Your server side should not be depend on your client's GUI.
You can/should use the standard Button with an attached ActionListener.

Now, if you really want to give your component an ID then you can simply extend the Button class.

public class MyButton extends Button()
private int id;
public MyButton(int id)
{
super()
this.id = id
}
//crate the other Button constructors similarly..
public int getID()
{
return id
}

null

ousys
Offline
Joined: 2008-05-14

Thank you for your reply , yep, follow your instruction , I think the component ID problem can be solved , but why isn't it a good design? because it is not a smart client?
but however, the client GUI is coming from the server side's xml , so is there any other better design? whether need to use RMS or not?

actually , now I am do my final year project, and I am not good at j2me--(maybe can say j2me beginner, has some j2se basis), so I expert for your advises and suggestions, thank you very much for solving my problem!

nafs
Offline
Joined: 2008-06-10

Well I am not sure what kind of design you have, but from your original post it seemed to me that you have something like:
button1.jsp (when button1 is clicked)
button2.jsp (when button 2 is clicked)
and so on..

Anyway, don't overthink it. Have fun tinkering.

chen

Hi,
Currently you can't attach a meta data to a Component, what you can do
is keep the textfields pointers yourself and react when the text has
been edited, use DataChangedListener to receive the callbacks from the
TextField

Regards,
Chen

lwuit-users@mobileandembedded.org wrote:
> Hello , is it possible to give each component an ID, and then I could do something like getTextFromID()....
> in my code , I declared one textfield,
> TextField tf;
> and I do such things,
> for(int i=0;i<=2;i++){
> tf=new TextField()
> form.addComponent(tf);
> }
> form.show();
>
> and in Display , they can actually display 3 TextField.
> But now I want to get the Text in each textfield , dunno how to implement , anybody can give my any idea?
>
> Thank you!
> [Message sent by forum member 'ousys' (ousys)]
>
> http://forums.java.net/jive/thread.jspa?messageID=286223
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net