15 March 2015
JavaFX is a software platform for creating Rich Internet Applications that can run across variety of platforms[1].It has a collection of Java Packages with ability to add fancy GUI to your Java application. JavaFX is official standard part of Java platform. JavaFX is considered as a successor of Swing and can be easily understood by a Swing developer. You can get the latest in JavaFX in early access preview of JavaFX in Java 8 EA 40
History: Formerly it was called in F3(Form Follows function) and developed by Oliver Smith at Sun Microsystems. JavaFX was initially developed as a scripting language however it was later discontinued by Oracle and declared dead in Java One 2010. Now JavaFX has a clean Java API.
JavaFX Lingo In order to understand JavaFX well one needs to familiarize with the Jargon used
Stage: Stage is implicitly created by JavaFX. JavaFX makes you think like a designer and stage is where you will host your scene
Scene:A scene is a hierarchical node structures that contains all scene’s components
Group:Group is general purpose container node. This is analogous to a layout creates
Various possibilities with JavaFX
package sampleapplication;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
*
* @author rvvaidya
*/
public class SampleApplication extends Application {
@Override
public void start(Stage primaryStage) {
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Code Walk through