I have a button that generates lottery numbers, wich i immediately set to a List and some NativeButton’s captions.
If you click the generate button that does this really fast, repeatedly, many times, for 5 seconds, the buttons that increment and decrement by 1 these numbers stop working, at first click either jumping by 20 at a time or so, doing nothing, but finally losing all functionality. EDIT: and it also loses the ability to throw errors such as Out of sync (the multiple tabs problem).
i also attached a test war for your convenience to import into eclipse as a project or deploy.
To get there, click “New Prognosis” > “Hybrid”, then click on “Generate” button fast for like 5 seconds.
The buttons that increment and decrement are above and below the numbers.
entry point:
public class OosApplication extends Application{
@Override
public void init() {
setTheme("mytheme");
setMainWindow(new Window("Realloto Application"));
getMainWindow().getContent().setSizeFull();
getMainWindow().getContent().addComponent(new LotoMainMenu());
}
}
[b]
everything else is in ExtractionHorizontalLayout
[/b]
generate button code:
generateButton.addListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
Random r = new Random(System.currentTimeMillis());
Set<Integer> set = new HashSet<Integer>();
while (set.size() < 6)
set.add(r.nextInt(48) + 1);
int i = 0;
for (Integer integer : set) {
nrs.add(integer);
nrButtons.get(i).setCaption(integer.toString());
i++;
}
}
});
an increment button’s code:
if (nativeButton == incrementNrs.get(0)) {
getNextValid(nrs.get(0) + 1, 0);
nrButtons.get(0).setCaption(nrs.get(0).toString());
algorythm that increments the values:
/**
* Saves the next valid number in the extraction number list.
*/
private void getNextValid(Integer next, Integer index){
boolean increasing = false;
// Determines if it's increasing by comparing i > nrs(index)-i
if (next > nrs.get(index))
increasing = true;
next = getNextValidWorker(next, increasing);
if (next < 50 && next > 0) {
nrs.set(index, next);
}
}
private Integer getNextValidWorker(Integer i, boolean increasing) {
if (i < 50 && i > 0) {
for(Integer nr: nrs) {
// if like another in the extraction
if(nr == i) {
// get next probable valid number
if (increasing)
i++;
else
i--;
// recurse to check new number validity
i = getNextValidWorker(i, increasing);
}
}
}
return i;
}
11323.war (3.4 MB)