I am just wondering… How to block main thread as JOptionPane (its confirmation dialog) does to be able hold execution until it returns some value? I’ve never done it before so I am interested to find an optimal way…
to be more clear I am interested to express the conception as something like this but I am not sure how to make it wait until an event happens in popupmenu for example:
...
int a;
int x;
void showPopup()
{
a=MyPopupMenu.aPopupMenu();
if(a==0){System.out.println("YES");}
if(a==1){System.out.println("NO"); return;}
x++;
}
Thanks
Use wait/notify. The main thread will do:
and the handler (ie listener) for whatever GUI you are using (a popup in your example) will do:
Here is a stripped-down instructional example using wait/notify