I have this class, let's say Foo
. This class is responsible for creating/showing a JFrame
, which requires heavy customization.
public class Foo{
private static JFrame frame;
public static void createAndShowFrame(){
//do stuff
}
public static JFrame getFrame(){
return frame;
}
}
And I have this other class, let's say Launcher
, that serves as the entry-point of the application. This class is responsible for initiating the construction of the GUI
public class Launcher{
public static void main(String[] args){
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run(){
Foo.createAndShowFrame();
}
});
}
}
The design problem is getFrame()
. This method was required because other dialogs require this as their parent frame. Unfortunately, this exposes the frame and seems to void the static-utility method.
I guess my question is, is there a more sound design approach to this? Am I making any sense? I basically wanted to create and show a frame without having to extend
it.
See my Rule of Thumb question.