I have seen this "design pattern" (don't know what else to call it.. template?) show up more than once in Java code. Application is expected to be extended and include a main method. I can't figure out what the benefit is of using Class instead of the AppFrame in the start method since it is just type casted to AppFrame anyways. It just all seems so pointless, maybe somebody can fill me in.
public class Application {
public static class AppPanel extends JPanel {
//stuff
}
public static class AppFrame extends JFrame {
protected AppPanel mainPanel;
//more stuff
}
public static AppFrame start(Class appFrame) {
try {
final AppFrame frame = (AppFrame) appFrame.newInstance();
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
frame.setVisible(true);
}
});
return frame;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static void main(String[] args){
Application.start(AppFrame.class);
}
}