How do you process command line arguments in java Swing Application Framework
I'm trying to grab the arguments passed form the command line when I run my application. I have a project made through netbeans that uses the SingleFrameApplication class or the swing application framework. The main method does a call
launch(MyApp.class, args);
in it's main method. The documentation found in http://java.sun.com/developer/technicalArticles/javase/swingappfr/ says that:
The launch method calls the application's optional initialize method just prior to calling the startup method. You can use the initialize method to perform any initial configuration or setup steps. For example, you can process command-line arguments from within the initialize method. You can also check a database connection or set system properties. In short, the framework provides this method for any non-UI related setup that your application may need before displaying the UI. The Application and SingleFrameApplication classes provide an empty method body for the initialize method. The method doe开发者_如何学Cs nothing by default.
Are we talking about the MyApp.initialize method here? If so, there doesn't seem to be any reference to the args parameter.
EDIT: This is not an applet, it's a desktop application. Remember, it's using the Swing Application Framework, which means that, part of this is to have a "launcher" class for you main java class GUI. A code snippet would be:
public class MyApp extends SingleFrameApplication {
@Override protected void startup() {
MyAppGUI view = new MyAppGUI(this);
show(new MyAppGUI(this));
}
public static void main(String[] args) {
launch(MyAppGUI.class, args);
}
Yes, you have to override the initialize(...)
method. In the link you have provided, there is Code Example 6
, showing the use of the initialize(...)
method. It clearly has the command line arguments in there.
public class HelloWorld extends SingleFrameApplication {
...
@Override
protected void initialize(String[] args) {
...
}
}
Taken from the official Sun docs. Add this to your application class.
@Override
protected void initialize(String[] args) {
...
}
精彩评论