Research Log of Web Science Students

Computer Science is not simply programming

Finally Speaking

with 2 comments

I have this certain code and I can’t seem to get the variable i plugged in to the MouseUpHandler. It seems that I cannot refer to a non-final variable inside an inner class.

for(int i = 0; i < activityCount; i++) {
activities.add(new VerticalPanel());
activities.get(i).add(new Label("Learning Activity #" + (i + 1)));

objectList.add(new VerticalPanel());

Button addLink = new Button("Add");
addLink.addMouseUpHandler(new MouseUpHandler() {
public void onMouseUp(MouseUpEvent event) {
addObject(i); // I CAN'T DO THIS!

And I haven’t figured out how to code-style-display the code above unlike what partner does.


Written by Paolo Sy

November 29, 2009 at 1:54 am

Posted in Hardwire

Tagged with , ,

2 Responses

Subscribe to comments with RSS.

  1. There’s a different way to do what you’re trying to do.

    Use the [/sourcecode] shortcode to display code in syntax highlighter

    Jose Asuncion

    November 29, 2009 at 4:42 am

  2. […] a comment » So instead of bothering with adding Listeners by iteration, we did an object-oriented approach […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: