Hello guys, this time I will share how to make JavaFX programs using Eclipse IDE, for beginners who need a guide to setup Eclipse IDE in making JavaFX programs maybe this can help,
Open Eclipse IDE and create a new project
File-> New -> Java Project
Add the JavaFX library in the Modulepath section, not in the Classpath section.
Next, create a package "com.intro" in the src folder
Setting Up a Module Info
In order for JavaFX to work properly in a modulated environment, we need to add module-info.java
files inside the src folder, which is the same as saying "we are using a modulated environment," we need to add the files
some entries in that file. Open it and change its contents to be like below:
module HelloFX {
requires javafx.graphics;
requires javafx.controls;
requires java.desktop;
requires javafx.swing;
requires javafx.media;
requires javafx.web;
requires javafx.fxml;
requires jdk.jsobject;
opens com.intro to javafx.graphics, javafx.base;
}
Create "HelloFXApp" class in "com.into" package
Write the following code
package com.intro;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
public class HelloFXApp extends Application{
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage stage) {
Text msg = new Text("Hello JavaFX");
VBox root = new VBox();
root.getChildren().add(msg);
Scene scene = new Scene(root, 300, 50);
stage.setScene(scene);
stage.setTitle("HelloFX Java App");
//show the stage
stage.show();
}
}
and then Run the application
0 تعليقات