My question deals with proper placement of code (if there is such a thing as proper placement).
In the code sample below, the About dialog is shown when a button is clicked, however the code from which the dialog is created is contained within the event listener attahced to the button! The code sample is from a skeleton file for a class project -- rules are that all code must be contained within one file.
My question is... ideally (ignoring the class project's rules)... where should the code to create the About dialog box be? Should I have created a class called AboutDialog that extends JFrame?
And what if I wanted to write code such that it wouldn't spawn additional About dialogs if one were already visible? I think I could just have a member variable of type AboutDialog and check to see if it were null every time the button to spawn an About dialog is clicked. Then, if it were null, initialize the dialog, if not, do nothing.
What I typically do is create a custom class that extends JFrame/JDialog/JWindow (whatever frame class you want) and then call that from my action. If you need to pass it parameters of any kind, just create a constructor that accepts whatever parameters you need.
As far as, if one were already visible, you would just need to keep track of that yourself in some kind of list. And check that list for the presence of a dialog already. If it's there, just bring the other dialog to the front.
major psuedo code:
This was just something I thougt at first attempt. Another option is to make your JDialog modal so that nothing else can be pressed unil that dialog is closed (typical common use of a JDialog). If this method does not suit your needs, consider the latter. [ October 06, 2004: Message edited by: Gregg Bolinger ]