7. • Java language features
• FXML for defining user interfaces
• New graphics pipeline for modern GPUs
• Rich set of UI controls
• Powerful Properties Model
• Swing and AWT Interoperability
8. JavaFX Public APIs and Scene Graph
Quantum Toolkit
Prism
Java 2D
Open GL
3D
Glass
Windowing
Toolkit
Media
Engine
Web
Engine
9. • Over 50+ components
• CSS skinning and layout
• Advanced UI controls
34. javafx.application.Application
public class HelloJavaFX extends Application {
Top level container
@Override
public void start(Stage stage) {
Root container
BorderPane root = new BorderPane();
Button btn = new Button("Hello JavaFX!");
root.setCenter(btn);
}
}
Place Button
Scene scene = new Scene(root, 300, 250);
stage.setScene(scene);
stage.show();
public static void main(String[] args) {
launch(args);
}
Run...
39. listener?
Button btn = new Button("Hello JavaFX!");
Generic Event type
Register
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
/* Do something */
Generic Event type
}
});
Override
40. final Circle circle = new Circle(radius, Color.RED);
circle.setOnMouseEntered(new EventHandler<MouseEvent>() {
public void handle(MouseEvent me) {
/* Do something */
}
});
circle.setOnMouseExited(new EventHandler<MouseEvent>() {
public void handle(MouseEvent me) {
/* Do something */
}
});
circle.setOnMousePressed(new EventHandler<MouseEvent>() {
public void handle(MouseEvent me) {
/* Do something */
}
});
handle
EventHandler
41. final Ellipse oval = new Ellipse(100, 50);
oval.setOnZoom(new EventHandler<ZoomEvent>() {...});
oval.setOnScroll(new EventHandler<ScrollEvent>() {...});
oval.setOnRotate(new EventHandler<RotateEvent>() {...});
42. • JavaBean Component architecture
• Expanded JavaBean properties
• In conjunction with Binding
43. Label mile = new Label();
KM to mile
double kmValue = 32.5;
double mileValue = kmValue * 0.621371192;
String mileText = Double.toString(kmValue);
mile.setText(mileText);
Set Label text
Double to String
44. KM Property Object
DoubleProperty kmPro = new SimpleDoubleProperty();
Label mile = new Label();
StringBinding Object,
hold KM to mile value
StringBinding mileBinding =
kmPro.multiply(0.621371192).asString();
mile.textProperty().bind(mileBinding);
...
Bind mile value
to Text Property
kmPro.set(32.5);
Change KM Property value
45. DoubleProperty kmPro = new SimpleDoubleProperty();
Label mile = new Label();
Extends Binding Class
StringBinding mileBinding = new StringBinding() {
{
Binding Property
super.bind(kmPro);
}
Override computeValue method
@Override
protected String computeValue() {
return Double.toString(kmPro.get() * 0.621371192);
}
Produce value here
};
mile.textProperty().bind(mileBinding);
...
kmPro.set(32.5);