The Elegant way to handle Cyclic Event in Java ??

Posted by dex on Stack Overflow See other posts from Stack Overflow or by dex
Published on 2010-03-08T03:31:59Z Indexed on 2010/03/08 3:36 UTC
Read the original article Hit count: 271

Filed under:
|
|
|
|

Hi fellows, i think this not a specific problem to me; everybody might have encountered this issue before. To properly illustrate it, here's a simple UI:

alt text

As you can see, those two spinners are controlling a single variable -- "A". The only difference is that they control it using different views.

If i change the top spinner, "A" will be changed and the bottom spinner's value will also be updated accordingly. However, updating the bottom spinner's call (such as setValue) will also trigger another event instructing the top spinner to update based on the bottom spinner's value. Thus creates a bad cycle which can eventually cause a StackOverFlow exception.

My previously solution is kinda cumbersome: i placed a guarding boolean to indicate whether the 2nd updating call should be performed.

Now i'd like to ask "how can i handle such situation elegantly?"

thx

© Stack Overflow or respective owner

Related posts about java

Related posts about swing