MovieBazar.Info

Latest News & Reviews

JavaFX : Java Graphical Interface . Read it For Knowledge .

We become annoyed to create a console app. Think of how to create a nice software. Beautiful software has beautiful graphical user interface. There is also a built-in class for creating a graphical user interface in Java. Such as Swing, Awt and JavaFX JavaFX is the latest GUI library. There are all the great api and great features. With the features we will be gradually known. Before knowing how to create a simple JavaFX project.

You can create JavaFX application using any text editor or IDE. I will show you how to create JavaFX programs using IntelliJ IDEA. Initially, install IntelliJ IDEA. If Java SE Development Kit is not installed, download and install Java SE Development Kit.

Open IntelliJ IDEA and click on Create Project. From here, many types of Java projects can be made. We will see how JavaFX programs can be created. If JDK Path is not set here, JDK will ask to set path. From Directory Selector, C: \ Program Files> Java> jdk1.8.0_51 will be set as such.

Select the JavaFX application and click on Next. Next step will be to give the name of the project and clicking on Finish will create a simple JavaFX project for us.

From the left side we can see the various project files. We can see three files in the src directory. By default Intellij IDEA has generated these files for us. Here is one Controller.java, one is Main. java is another example sample.fxml (View) Contact the work of the main.java logic and view the file. Controller.java will not even worry about it.

When we open the sample.fxml file, we get two options. One is the text mood. Another is the Scene Builder Mood. In Scene Builder mode we can add any widget to our view. You can see many widgets on the right, such as Button, Checkbox, ChoiceBox, ImageView etc. We can add them to the view and work with them. The Initial Scene Builder does not contain anything. You can drag and drop any widget if you wish.

Come back to main.java. What will appear in the view file, what happens when clicked, all of these are controlled from here. The code below includes the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

 import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

@Override
public void start (Stage primaryStage) throws exception {
Parent root = FXMLLoader.load (getClass (). GetResource (“sample.fxml”));
primaryStage.setTitle (“Hello World”);
primaryStage.setScene (new Scene (root, 300, 275));
primaryStage.show ();
}

public static void main (string [] args) {
launch (args);
}
}


Parent root = FXMLLoader.load (getClass (). GetResource (“sample.fxml”)); The view file was connected to.
The title of the application with primaryStage.setTitle (“Hello World”) has been set.
The primaryStage.setScene (new, Scene, root, 300, 275) is set to be the width & height of the application. The final application frame with primaryStage.show () is shown. Click on Run from the Run menu to see the app with our graphical user interface first. Or you can run from the toolbar by clicking on Play button.

Please see any views in Builder . Then run the project and see it.

Leave a Reply

Your email address will not be published. Required fields are marked *

MovieBazar.Info © 2018