Hello to all 3 people who read my blogs. Today I want to share with you the most recent reasons for my ever-so-constant headaches, JavaFX. JavaFX is a powerful framework for building graphical user interfaces (GUIs) in Java. The main reason why I’m dedicating time to it is that I need to hone my skills to make one of my projects more user-friendly and a tad bit more professional and appealing.
One of the first challenges I faced while beginning to work with it was the actual setup. Many different IDEs require a different set of requirements to be installed or added before using a specific language or module. In my personal case, setting up JavaFX with my preferred IDE which is IntelliJ proved to be a little more challenging than usual as the video tutorial I was following had an older version of both JavaFX and IntelliJ which had fewer options than my versions which made it hard to find the correct “buttons” to set everything up, but nevertheless I made it work.
When the time came to actually create the interfaces I’ll admit that I was a little overwhelmed as I did not even know where to start, but following free online tutorials helped me a lot to create my first interface. Here is a sample of what JavaFX code looks like.
// Sample code for creating a simple JavaFX UI
public class MyJavaFXApp extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("My JavaFX App");
Button btn = new Button("Click me!");
btn.setOnAction(e -> System.out.println("Button clicked!"));
StackPane root = new StackPane();
root.getChildren().add(btn);
primaryStage.setScene(new Scene(root, 300, 200));
primaryStage.show();
}
}
This code creates a new window that has a single button that says “Click Me!”
It may not look like much but after spending close to three hours just setting everything up, ending with this feels like a great achievement.
Unfortunately, the project that I am working on requires far more functionality as it is meant to do something meaningful and useful (Stay Tuned for the project blog), so my next milestone into the JavaFX journey is going to be adding this functionality and handling the different user-oriented events that will be in the framework of my project.
In conclusion, learning about JavaFX has been a very enlightening experience. I have only scratched the surface of what this framework can do but needless to say, I’m happy with my progress and far more excited about learning more in the future. If any of you fellow students are interested in GUI programming with JavaFX, I highly recommend giving it a try as there are a lot of possibilities with it and apparently, the learning curve is very rewarding.
Till next time. Ano out.
From the blog CS@Worcester – Anairdo's WSU Computer Science Blog by anairdoduri and used with permission of the author. All other rights reserved by the author.