I'm wondering why my programs in Swing can run at every machine which have Java installed, but JavaFX programs not. If I want to run my program in JavaFX i have to copy some JavaFX library files to JDK folder like here. The problem is: I don't want to force people to move some files into any folder! I want them to be able run the program just by clicking it and nothing else! I want to make it simple. Other Programs in Java don't force me to do that so how can i make my program like others? What should i do? Here are some example of code.
Main.java
package fxTutorial;
public class Main {
public static void main(String[] args){
Demo.main(args);
}
}
Demo.java
package fxTutorial;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Demo extends Application implements EventHandler {
Button button = new Button();
public static void main(String[] args){
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Application");
button.setText("Button");
button.setOnAction(this);
StackPane stackPane = new StackPane();
stackPane.getChildren().add(button);
Scene scene = new Scene(stackPane,400,500);
primaryStage.setScene(scene);
primaryStage.show();
}
@Override
public void handle(Event event) {
if(event.getSource()==button)
//Do something, like background changing - Whatever
}
}
module-info.java
module Demo {
requires javafx.fxml;
requires javafx.controls;
opens fxTutorial;
}