Skip to content
Advertisement

How to increment numbers using Event Listeners and Widget Viewer in Java?

I’m writing a WidgetViewer GUI where when the “go up/up” button is pushed, a random number between 1 and 10 (inclusive) is generated and added to the left label, and another random number between 1 and 10 (inclusive) is generated and added to the right label.

The widgets required are: a button labeled “go up/up”, a label initialized to 0 (left label), and a label initialized to 0 (right label).

This is what I have so far:

JavaScript

However, when I run this and when I click the button, it only shows a new number each time without adding to it. How can I make it increment each time?

Advertisement

Answer

left value is processed correcty, the right value is calculated correctly too … but stored in the ui-element of the left value …

JavaScript

=> overwriting the just previously correct left value, resetting it. just replace with

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement