View RSS Feed

A JavaFX Blog

How to Launch a JavaFX Application

Rate this Entry
by , 12-09-2016 at 06:13 PM (5617 Views)
The javafx.application.Application class, which defines a JavaFX application, can be launched by calling one of its two static launch() methods:

  • public static void launch(String... args)
  • public static void launch(Class<? extends Application> appClass, String... args)


The first method takes as argument a set of application parameters, while the second method takes an additional argument indicating an Application subclass. The difference between the two methods is that the first one uses the calling class’ implementation as Application class (so it must be called from within a class which subclasses Application), while the second one supplies explicitly the class to be used as Application implementation, so it can be called from within any class. For example, if the class MyApplication subclasses Application, it can launch the JavaFX application using the first launch() method:

Java Code:
public class MyApplication extends Application {
  public static void main(String... args) {
    launch(args);
  }
  ...
}
The call to launch() in the above example is equivalent to calling launch(MyApplication.class, args). But if the JavaFX application is launched from another class which does not subclass Application, the above launch() method cannot be used, and the other launch() method must be used instead, passing it MyApplication.class as first argument:


Java Code:
public class AnotherClass {
  public static void main(String... args) {
    Application.launch(args);	// error!
    Application.launch(MyApplication.class, args);	// correct
  }
  ...
}

Submit "How to Launch a JavaFX Application" to Facebook Submit "How to Launch a JavaFX Application" to Digg Submit "How to Launch a JavaFX Application" to del.icio.us Submit "How to Launch a JavaFX Application" to StumbleUpon Submit "How to Launch a JavaFX Application" to Google

Updated 12-11-2016 at 05:34 PM by JavaFX

Tags: None Add / Edit Tags
Categories
JavaFX Application