Jump to content

JavaFX and OSBot


Butters

Recommended Posts

I'm trying to make a bot GUI with JavaFX instead of swing. Well you know, looks 10x sexier. Though I ran into a ton of problems.

 

First things first, is it even possible to properly use JavaFX in OSbot instead of Swing without going through hell?

 

I've called the GUI like this

Application.launch(Test.class);

Cause this doesn't even bother to work 

Test test = new Test(Script s);
test.launch(Test.class); // Tried with null - the same

// Getting cannot be launched more than once exception

Any idea how to pass GUI parameters between the interface and the bot code? Or shouldn't I even bother and write everything in Swing?

Link to comment
Share on other sites

I'm trying to make a bot GUI with JavaFX instead of swing. Well you know, looks 10x sexier. Though I ran into a ton of problems.

 

First things first, is it even possible to properly use JavaFX in OSbot instead of Swing without going through hell?

 

I've called the GUI like this

Application.launch(Test.class);

Cause this doesn't even bother to work 

Test test = new Test(Script s);
test.launch(Test.class); // Tried with null - the same

// Getting cannot be launched more than once exception

Any idea how to pass GUI parameters between the interface and the bot code? Or shouldn't I even bother and write everything in Swing?

 

This is how you integrate JavaFX into a Swing application: https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/swing-fx-interoperability.htm

 

It's probably safer to just use Swing though

Edited by Explv
  • Like 1
Link to comment
Share on other sites

Like which? I've never heard this before.

 

 

It's simply not supported by every JVM implementation, if a context (up to the OS scope) forces you to use a JVM that doesn't provide / isn't compatible with JFX runtimes, you're fucked. 

 

Arch, Bodhi, Gentoo, Slackware are some I remember causing troubles (maybe some of them support it now), I'm sure there are plenty of others. 

 

On top of this, part of the JavaFX architecture relies on OpenGL, not all operating systems have available drivers for this (I've heard horror stories about companies having to write their own... ew).

 

jfxar_dt_001_arch-diag.png

 

Honestly, writing desktop clients in Java is very much a thing of the past. 

Edited by Botre
  • Like 1
Link to comment
Share on other sites

It's simply not supported by every JVM implementation, if a context (up to the OS scope) forces you to use a JVM that doesn't provide / isn't compatible with JFX runtimes, you're fucked. 

 

Arch, Bodhi, Gentoo, Slackware are some I remember causing troubles (maybe some of them support it now), I'm sure there are plenty of others. 

 

On top of this, part of the JavaFX architecture relies on OpenGL, not all operating systems have available drivers for this (I've heard horror stories about companies having to write their own... ew).

 

jfxar_dt_001_arch-diag.png

 

Honestly, writing desktop clients in Java is very much a thing of the past. 

 

Well most of which that doesn't support JavaFX are server environments like Solaris, JavaFX is for Clients. I don't believe a lack of support for a couple Linux systems is a reason for him to disregard JavaFX altogether.

Edited by Thunderwaffe
Link to comment
Share on other sites

Well most of which that doesn't support JavaFX are server environments like Solaris, JavaFX is for Clients. I don't believe a lack of support for a couple Linux systems is a reason for him to disregard JavaFX altogether.

 

Many people on this site use what you call server-oriented operating systems on their VPS.

 

Another case:

CentOS uses OpenJDK  which supports JFX but doesn't bundle it by default, this means he would have to ask those users to to install another JDK (if their VPS provider allows this at all)  or somehow install the runtimes manually.

 

If he wants to release his script publicly he should seriously reconsider the idea of JFX, if not then ofcourse none of what I said is really relevant :p

Link to comment
Share on other sites

It is possible.

 

Here's my old code. Sorry there's a lot of unrelated junk. I cbf to clean it for you. Basically, like Villius said, you gotta wrap with JFXPanel.

 

Also, I dev-ed this on Linux. It is supported, if you're using Oracle JDK at least... Most Linux distros have a package for it. If not, they're probably using a less user-friendly distro, and I'd assume that means they're experienced enough to install it manually.

// Display the GUI
            JFXPanel panel = new JFXPanel();
            JFrame frame = new JFrame();
            try {
                panel.setScene(new SupremeFisherGUI().load(frame, this));
            } catch (Exception e) {
                e.printStackTrace();
            }
            frame.setUndecorated(true);
            frame.setSize(328, 240);
            frame.setContentPane(panel);
            frame.setVisible(true);
            frame.setBackground(new Color(0, 0, 0, 0));

and then I have this:

 

public Scene load(JFrame stage, Main script) throws Exception {
MainGUIController controller = new MainGUIController();

AnchorPane anchorPane = new AnchorPane();
anchorPane.setPrefSize(320.0, 174.0);
anchorPane.setStyle("-fx-background-color: #000");

Label welcomeLabel = new Label("Welcome to SupremeFisher!");
welcomeLabel.setTextFill(Paint.valueOf("#55acee"));
welcomeLabel.setFont(new Font("Cambria Bold", 18.0));
welcomeLabel.setLayoutX(16);
welcomeLabel.setLayoutY(6);
anchorPane.getChildren().add(welcomeLabel);

Label optionsLabel = new Label("Please configure your options below:");
optionsLabel.setFont(new Font("Cambria", 14.0));
optionsLabel.setTextFill(Paint.valueOf("#FFFFFF"));
optionsLabel.setLayoutX(18.0);
optionsLabel.setLayoutY(29.0);
anchorPane.getChildren().add(optionsLabel);

Label locationLabel = new Label("Location:");
locationLabel.setTextFill(Paint.valueOf("#55acee"));
locationLabel.setFont(new Font("Cambria", 14.0));
locationLabel.setLayoutX(18.0);
locationLabel.setLayoutY(59.0);
anchorPane.getChildren().add(locationLabel);

controller.locationBox = new ComboBox<>();
controller.locationBox.setLayoutX(87);
controller.locationBox.setLayoutY(56);
controller.locationBox.setPrefHeight(27.0);
controller.locationBox.setPrefWidth(215.0);
controller.locationBox.setPromptText("Select a Location");
controller.locationBox.setStyle("-fx-border-color: #55acee; -fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-border-radius: 10; -fx-padding: 0 0 0 4;");
anchorPane.getChildren().add(controller.locationBox);

controller.fishLabel = new Label();
controller.fishLabel.setLayoutX(18.0);
controller.fishLabel.setLayoutY(125);
controller.fishLabel.setFont(new Font("Cambria", 14.0));
controller.fishLabel.setTextFill(Paint.valueOf("#55acee"));
anchorPane.getChildren().add(controller.fishLabel);

controller.fishView = new ListView<>();
controller.fishView.setLayoutX(18.0);
controller.fishView.setLayoutY(152);
controller.fishView.setMaxHeight(100.0);
controller.fishView.setMinHeight(0.0);
controller.fishView.setPrefHeight(0.0);
controller.fishView.setPrefWidth(285);
controller.fishView.setStyle("-fx-background-color: #000000; -fx-border-color: #55acee;");
anchorPane.getChildren().add(controller.fishView);

controller.typeBox = new ComboBox<>();
controller.typeBox.setLayoutX(87);
controller.typeBox.setLayoutY(89);
controller.typeBox.setPrefHeight(27);
controller.typeBox.setPrefWidth(215.0);
controller.typeBox.setPromptText("Select a Type");
controller.typeBox.setStyle("-fx-border-color: #55acee; -fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-border-radius: 10; -fx-padding: 0 0 0 4;");
anchorPane.getChildren().add(controller.typeBox);

Label typeLabel = new Label("Type:");
typeLabel.setLayoutX(18.0);
typeLabel.setLayoutY(94.0);
typeLabel.setTextFill(Paint.valueOf("#55acee"));
typeLabel.setFont(new Font("Cambria", 14.0));
anchorPane.getChildren().add(typeLabel);

controller.imageView = new javafx.scene.image.ImageView();
controller.imageView.setFitWidth(285.0);
controller.imageView.setLayoutX(18.0);
controller.imageView.setLayoutY(158.0);
controller.imageView.setPickOnBounds(true);
controller.imageView.setPreserveRatio(true);
anchorPane.getChildren().addAll(controller.imageView);

controller.reducedAntiban = new CheckBox("Reduced antiban mode (not recommended)");
controller.reducedAntiban.setTextFill(Paint.valueOf("#55acee"));
controller.reducedAntiban.setFont(new Font("Cambria", 14.0));
controller.reducedAntiban.setLayoutX(18.0);
controller.reducedAntiban.setLayoutY(141);
anchorPane.getChildren().addAll(controller.reducedAntiban);

controller.startButton = new Button("START");
controller.startButton.setDisable(true);
controller.startButton.setLayoutX(12.0);
controller.startButton.setLayoutY(176);
controller.startButton.setMnemonicParsing(false);
controller.startButton.setPrefHeight(27.0);
controller.startButton.setPrefWidth(297.0);
controller.startButton.setStyle("-fx-background-color: #000000; -fx-border-color: #55acee; -fx-border-radius: 10;");
controller.startButton.setTextFill(Paint.valueOf("#FFFFFF"));
anchorPane.getChildren().add(controller.startButton);

controller.locationBox.setOnAction(new EventHandler<ActionEvent>() {
@[member='Override']
public void handle(ActionEvent event) {
controller.updateLocation(event);
}
});
controller.typeBox.setOnAction(new EventHandler<ActionEvent>() {
@[member='Override']
public void handle(ActionEvent event) {
controller.updateType(event);
}
});
controller.startButton.setOnAction(new EventHandler<ActionEvent>() {
@[member='Override']
public void handle(ActionEvent event) {
controller.start(event);
}
});
controller.fishView.setOnMousePressed(new EventHandler<MouseEvent>() {
@[member='Override']
public void handle(MouseEvent event) {
controller.updateFishView(event);
}
});

Scene scene = new Scene(anchorPane, Color.TRANSPARENT);

controller.registerStage(stage, script);

return scene;
}
Edited by Ericthecmh
  • Like 4
Link to comment
Share on other sites

 

It is possible.

 

Here's my old code. Sorry there's a lot of unrelated junk. I cbf to clean it for you. Basically, like Villius said, you gotta wrap with JFXPanel.

 

Also, I dev-ed this on Linux. It is supported, if you're using Oracle JDK at least... Most Linux distros have a package for it. If not, they're probably using a less user-friendly distro, and I'd assume that means they're experienced enough to install it manually.

// Display the GUI
            JFXPanel panel = new JFXPanel();
            JFrame frame = new JFrame();
            try {
                panel.setScene(new SupremeFisherGUI().load(frame, this));
            } catch (Exception e) {
                e.printStackTrace();
            }
            frame.setUndecorated(true);
            frame.setSize(328, 240);
            frame.setContentPane(panel);
            frame.setVisible(true);
            frame.setBackground(new Color(0, 0, 0, 0));

and then I have this:

 

public Scene load(JFrame stage, Main script) throws Exception {
MainGUIController controller = new MainGUIController();

AnchorPane anchorPane = new AnchorPane();
anchorPane.setPrefSize(320.0, 174.0);
anchorPane.setStyle("-fx-background-color: #000");

Label welcomeLabel = new Label("Welcome to SupremeFisher!");
welcomeLabel.setTextFill(Paint.valueOf("#55acee"));
welcomeLabel.setFont(new Font("Cambria Bold", 18.0));
welcomeLabel.setLayoutX(16);
welcomeLabel.setLayoutY(6);
anchorPane.getChildren().add(welcomeLabel);

Label optionsLabel = new Label("Please configure your options below:");
optionsLabel.setFont(new Font("Cambria", 14.0));
optionsLabel.setTextFill(Paint.valueOf("#FFFFFF"));
optionsLabel.setLayoutX(18.0);
optionsLabel.setLayoutY(29.0);
anchorPane.getChildren().add(optionsLabel);

Label locationLabel = new Label("Location:");
locationLabel.setTextFill(Paint.valueOf("#55acee"));
locationLabel.setFont(new Font("Cambria", 14.0));
locationLabel.setLayoutX(18.0);
locationLabel.setLayoutY(59.0);
anchorPane.getChildren().add(locationLabel);

controller.locationBox = new ComboBox<>();
controller.locationBox.setLayoutX(87);
controller.locationBox.setLayoutY(56);
controller.locationBox.setPrefHeight(27.0);
controller.locationBox.setPrefWidth(215.0);
controller.locationBox.setPromptText("Select a Location");
controller.locationBox.setStyle("-fx-border-color: #55acee; -fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-border-radius: 10; -fx-padding: 0 0 0 4;");
anchorPane.getChildren().add(controller.locationBox);

controller.fishLabel = new Label();
controller.fishLabel.setLayoutX(18.0);
controller.fishLabel.setLayoutY(125);
controller.fishLabel.setFont(new Font("Cambria", 14.0));
controller.fishLabel.setTextFill(Paint.valueOf("#55acee"));
anchorPane.getChildren().add(controller.fishLabel);

controller.fishView = new ListView<>();
controller.fishView.setLayoutX(18.0);
controller.fishView.setLayoutY(152);
controller.fishView.setMaxHeight(100.0);
controller.fishView.setMinHeight(0.0);
controller.fishView.setPrefHeight(0.0);
controller.fishView.setPrefWidth(285);
controller.fishView.setStyle("-fx-background-color: #000000; -fx-border-color: #55acee;");
anchorPane.getChildren().add(controller.fishView);

controller.typeBox = new ComboBox<>();
controller.typeBox.setLayoutX(87);
controller.typeBox.setLayoutY(89);
controller.typeBox.setPrefHeight(27);
controller.typeBox.setPrefWidth(215.0);
controller.typeBox.setPromptText("Select a Type");
controller.typeBox.setStyle("-fx-border-color: #55acee; -fx-background-color: #000000; -fx-text-fill: #FFFFFF; -fx-border-radius: 10; -fx-padding: 0 0 0 4;");
anchorPane.getChildren().add(controller.typeBox);

Label typeLabel = new Label("Type:");
typeLabel.setLayoutX(18.0);
typeLabel.setLayoutY(94.0);
typeLabel.setTextFill(Paint.valueOf("#55acee"));
typeLabel.setFont(new Font("Cambria", 14.0));
anchorPane.getChildren().add(typeLabel);

controller.imageView = new javafx.scene.image.ImageView();
controller.imageView.setFitWidth(285.0);
controller.imageView.setLayoutX(18.0);
controller.imageView.setLayoutY(158.0);
controller.imageView.setPickOnBounds(true);
controller.imageView.setPreserveRatio(true);
anchorPane.getChildren().addAll(controller.imageView);

controller.reducedAntiban = new CheckBox("Reduced antiban mode (not recommended)");
controller.reducedAntiban.setTextFill(Paint.valueOf("#55acee"));
controller.reducedAntiban.setFont(new Font("Cambria", 14.0));
controller.reducedAntiban.setLayoutX(18.0);
controller.reducedAntiban.setLayoutY(141);
anchorPane.getChildren().addAll(controller.reducedAntiban);

controller.startButton = new Button("START");
controller.startButton.setDisable(true);
controller.startButton.setLayoutX(12.0);
controller.startButton.setLayoutY(176);
controller.startButton.setMnemonicParsing(false);
controller.startButton.setPrefHeight(27.0);
controller.startButton.setPrefWidth(297.0);
controller.startButton.setStyle("-fx-background-color: #000000; -fx-border-color: #55acee; -fx-border-radius: 10;");
controller.startButton.setTextFill(Paint.valueOf("#FFFFFF"));
anchorPane.getChildren().add(controller.startButton);

controller.locationBox.setOnAction(new EventHandler<ActionEvent>() {
@[member='Override']
public void handle(ActionEvent event) {
controller.updateLocation(event);
}
});
controller.typeBox.setOnAction(new EventHandler<ActionEvent>() {
@[member='Override']
public void handle(ActionEvent event) {
controller.updateType(event);
}
});
controller.startButton.setOnAction(new EventHandler<ActionEvent>() {
@[member='Override']
public void handle(ActionEvent event) {
controller.start(event);
}
});
controller.fishView.setOnMousePressed(new EventHandler<MouseEvent>() {
@[member='Override']
public void handle(MouseEvent event) {
controller.updateFishView(event);
}
});

Scene scene = new Scene(anchorPane, Color.TRANSPARENT);

controller.registerStage(stage, script);

return scene;
}

 +1 For showing a working example.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...