I have a question about coding style. I have always done the following and
I am wondering if such a thing is a good coding practice or if there is
something better. Here is the scenario:
class A extends JFrame
/*this is a window with a JList and 2 JButtons(OK/CANCEL).
I have several methods: 2 that set the ActionListeners for the
two buttons(they have none of their own and must be set from the calling
class)
and one that returns the selected
string from the JList.
*/
class B
/* This contains the main method which instantiates class B.
In the constructor, class A is instantiated and the ActionListeners
are defined and set for A's buttons.
main looks like this
{
B binstance = new B();
}
*/
When OK is clicked the action listener calls A's getSelection method which
returns the string selected. The action listener sets a static String in B
to the selected value(inside the actionPerformed method). The program
cannot continue until the static String is not null.
My question is this: should I call the next part of my program from inside
the action listener or should I use a loop like this:
while(true)
{
if(staticString!=null)
{
break;
}
}
/*call next part of program*/
Thanks a lot everyone.