Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Question How exactly does EmbeddableUI work?

Joined
Apr 25, 2019
Messages
3
I'm in the process of making a very simple bot and wanted to add a ui so I noticed that in the api EmbeddableUI uses JavaFX. There isn't much info about the class in the docs though so I started reading about Javafx and looked around through a few open source bots and have a few questions.

1) Normally in JavaFX for your class, you have to extend Application and you have a start method where you can set the stage and scene. I guess EmbeddableUI already extends Application but I cant seem to find an example where it sets the stage or scene.

2) What exactly does the botInterfaceProperty as an ObjectProperty do? Reading through the Javafx api which is kind of confusing for a newbie, it looks like javafx uses special properties instead of regular fields I'm guessing for some sort of additional functionality?

3) For the FXMLloader, why does Runemate use its own Resource class to get the fxml file? It also looks like loading the fxml file is very different.


For example, when looking at examples of javafx programs on the web, this is what normally comes up.
Code:
 @Override
    public void start(Stage stage) throws Exception
    {
        Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
    
        Scene scene = new Scene(root);
    
        stage.setScene(scene);
        stage.show();
    }

but in Runemate it would be something like:
Code:
public ObjectProperty<Node> botInterfaceProperty()
{
    if (botInterfaceProperty == null)
    {
        FXMLLoader loader = new FXMLLoader();
        try
        {
            Node node = loader.load(Resources.getAsStream("com/juggy3/bots/bones_burier_bot/BoneBurier.fxml"));
            botInterfaceProperty = new SimpleObjectProperty<>(node);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

    return botInterfaceProperty;
}
 
Last edited:
Joined
Apr 27, 2019
Messages
11
1) Normally in JavaFX for your class, you have to extend Application and you have a start method where you can set the stage and scene. I guess EmbeddableUI already extends Application but I cant seem to find an example where it sets the stage or scene.

The stage and scene are already set in RuneMate (from my understanding), and you're loading your UI into that. Incidentally, this is something that I'm having some issues with myself for some more complex reasons, although the concept itself is pretty straightforward. RuneMate development is my only experience with JavaFX, but the concepts seem incredibly similar to the WPF stuff that I've got a lot of experience with in .Net.

2) What exactly does the botInterfaceProperty as an ObjectProperty do? Reading through the Javafx api which is kind of confusing for a newbie, it looks like javafx uses special properties instead of regular fields I'm guessing for some sort of additional functionality?

Seems like you might not be familiar with bindings? Essentially "Property" fields are variables wrapped in a special class that lets you subscribe and automatically notify subscribers of changes to the value inside them. For example, if my bot has multiple UI "pages," all I have to do is drop the new page into the existing ObjectProperty<Node>, and then the interface you see in RuneMate is immediately updated, since the display of the bot UI is bound to the botInterfaceProperty.

These bindings work with pretty much everything, so you can declare a SimpleStringProperty (call it myString) in a class, then do Bindings.bindBidirectional(textField.textProperty(), myString), and if the TextField's text is updated in the UI the bound property's underlying value will be updated for your code OR if the value of the property is updated from the code, the value you see on the interface is automatically updated.

3) For the FXMLloader, why does Runemate use its own Resource class to get the fxml file? It also looks like loading the fxml file is very different.

Class.getResourceAsStream is disallowed in RuneMate bots for security reasons. Thus the manner in which you load the FXML file is a bit different.
 
Joined
Apr 25, 2019
Messages
3
The stage and scene are already set in RuneMate (from my understanding), and you're loading your UI into that. Incidentally, this is something that I'm having some issues with myself for some more complex reasons, although the concept itself is pretty straightforward. RuneMate development is my only experience with JavaFX, but the concepts seem incredibly similar to the WPF stuff that I've got a lot of experience with in .Net.



Seems like you might not be familiar with bindings? Essentially "Property" fields are variables wrapped in a special class that lets you subscribe and automatically notify subscribers of changes to the value inside them. For example, if my bot has multiple UI "pages," all I have to do is drop the new page into the existing ObjectProperty<Node>, and then the interface you see in RuneMate is immediately updated, since the display of the bot UI is bound to the botInterfaceProperty.

These bindings work with pretty much everything, so you can declare a SimpleStringProperty (call it myString) in a class, then do Bindings.bindBidirectional(textField.textProperty(), myString), and if the TextField's text is updated in the UI the bound property's underlying value will be updated for your code OR if the value of the property is updated from the code, the value you see on the interface is automatically updated.



Class.getResourceAsStream is disallowed in RuneMate bots for security reasons. Thus the manner in which you load the FXML file is a bit different.

Thanks a lot for elaborating. Still a bit confused on it but the more I code the more I'll probably become familiar with these things. Also I was unaware of bindings so thats a neat topic.
 
Top