- JavaFX is a framework for creating graphical user interfaces (GUIs) in Java.
- It provides a set of APIs for building rich, cross-platform graphical applications that can run on desktop computers, web browsers, and mobile devices.
- JavaFX provides a wide range of UI components, such as buttons, text fields, labels, tables, and charts, and it also includes built-in animations, effects, and multimedia support.
Below is a simple example of a JavaFX program that displays a car:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; public class CarExample extends Application { @Override public void start(Stage primaryStage) { StackPane root = new StackPane(); Rectangle body = new Rectangle(100, 50, Color.BLUE); root.getChildren().add(body); Scene scene = new Scene(root, 300, 250); primaryStage.setTitle("Car Example"); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } } |
In this example, we create a StackPane
as the root container for our car. A Rectangle
object is created to represent the car’s body, and it is added to the root container. Finally, a scene is created using the root container and displayed on the stage. This is just a simple example, and you can use more advanced features of JavaFX to create more sophisticated and interactive GUIs.