Java Reference
In-Depth Information
If you have read the previous chapters in this topic, the code of this application has no secrets anymore. We create
a StackPane containing a button and a label. The label is positioned below the button. An EventHandler is added to
the button. When the button is clicked, the code in the EventHandler will cause the text of the label to be changed to a
random day.
As mentioned before, converting this JavaFX Application into a native iOS application can be done in a number
of ways. We will use the maven approach here, as it turns out to be a simple way to create and run iOS applications.
Before we can create the iOS application, we need a launcher class. The code in Listing 12-2 shows what a
launcher for a RoboVM iOS application looks like.
Listing 12-2. Launcher Class for iOS Application
package projavafx;
import javafx.application.Application;
import org.robovm.cocoatouch.foundation.NSAutoreleasePool;
import org.robovm.cocoatouch.foundation.NSDictionary;
import org.robovm.cocoatouch.uikit.UIApplication;
import org.robovm.cocoatouch.uikit.UIApplicationDelegate;
public class SimplePortJFXLauncher extends UIApplicationDelegate.Adapter {
@Override
public boolean didFinishLaunching(UIApplication application, NSDictionary launchOptions) {
Thread launchThread = new Thread() {
@Override
public void run() {
Application.launch(SimplePort.class);
}
};
launchThread.setDaemon(true);
launchThread.start();
return true;
}
public static void main(String[] args) throws Exception {
System.setProperty("glass.platform", "ios");
System.setProperty("prism.text", "native");
NSAutoreleasePool pool = new NSAutoreleasePool();
UIApplication.main(args, null, SimplePortJFXLauncher.class);
pool.drain();
}
}
The main method of this launcher class contains some iOS-specific code. Note that we could add even more
iOS-specific code, but this is outside the scope of what we want to address here.
The didFinishLaunching callback handler will launch the JavaFX Application by calling the static launch method
on the javafx.application.Application class, thereby providing the classname of the JavaFX Application.
Now we have all the required code we need to build, test, and run the application. The RoboVM maven plug-in
is a nice tool for doing this. We need a pom file that will get the RoboVM maven plug-in and configure the goals.
The code for this pom file is shown in Listing 12-3.
 
Search WWH ::




Custom Search