Can't figure saving out.

0 views
Skip to first unread message

Loki

unread,
Nov 17, 2008, 11:29:16 PM11/17/08
to Google Web Toolkit
Perhaps my brain is just fried-- the longer I code, the less sense
coding seems to make to me, so maybe I just need a break, but I'll
list my problem just in case I'm wrong.

Okay, so I have a setup where a user enters data into a bunch of
various textboxes, and there's a button labeled "Save" waiting for the
user at the end of it all. However, with the way the button is set
up--

Button save = new Button("Save",
new ClickListener() {
public void onClick(Widget sender) {

}
});

And then later,

panel.add(save);

it seems to me that I can't really put anything in the onClick()
method that will actually allow me to access all those various
textboxes I have elsewhere without making, like, EVERY textbox a
global variable, which is just nonsense.

SUMMARY: wut do i do guyz

gregor

unread,
Nov 18, 2008, 6:28:59 AM11/18/08
to Google Web Toolkit
public class MyComponent {
private SimplePanel panel = new SimplePanel();
private textBox = new TextBox();
private Button myButton = new Button("Save",
new ClickListener() {
public void onClick(Widget sender) {
String data = textBox.getText()
}
});

public MyComponent {
panel.add(textBox);
panel.add(myButton);
}

Instance variables declared in MyComponent are directly available like
this. if panel was a separate class then you would need to do
something like:

panel.getTextBox().gettext();

regards
gregor

alex.d

unread,
Nov 18, 2008, 7:40:17 AM11/18/08
to Google Web Toolkit
If "all those various textboxes" are in the same class then you just
have to make them PRIVATE - not global. If they are in other Classes
then you have to make them PUBLIC(bad style) or provide a bunch of
public GET/SET Methods(good style). Another way is to declare them
("all those various textboxes") BEFORE you've declared your button
(like gregore showed you).

Reinier Zwitserloot

unread,
Nov 18, 2008, 8:22:58 AM11/18/08
to Google Web Toolkit
Loki, like the compiler error says:

make them final.

e.g.:

final textArea text = new TextArea();
final Button save = new Button(whatever);
Reply all
Reply to author
Forward
0 new messages