Hi Friends,
In previous post i was provided you an small introduction to JavaFX. Lets see an example based on JavaFX. Hope you have downloaded and setup IntelliJ Idea IDE.
Note: This example is based on only java classes(Pure java Example).
Setting up the JavaFX project(Gradle based)
This is a basic example of JavaFX. Hope this will be helpful to you.
Keep reading my blog and send me your suggestions. Thankx :)
In previous post i was provided you an small introduction to JavaFX. Lets see an example based on JavaFX. Hope you have downloaded and setup IntelliJ Idea IDE.
Note: This example is based on only java classes(Pure java Example).
Setting up the JavaFX project(Gradle based)
- Go to File-> New-> Project and click.One popup dialog will appear.
- On left panel of dialog, click on gradle.
- On right panel you will see some check boxes. Select Java and click Next.
- You will asked to fill some text fields.
- Enter project's package name in GroupId(i.e com.coderzduniya.fxdemo).
- Enter project name in ArtifactId(i.e JavaFX Demo).
- Leave Version as it is and go to Next.
- Go to Next again and Finish.
- After doing it well your project will be created.
- Now right click on java folder inside src/main and go to New-> JavaFXApplication
- Enter the class name(i.e Main) and click OK.
Now copy the following code and paste inside your start method(Method start(...) will be created automatically).
I have explained the structure and Code flow in video tutorial.
I have explained the structure and Code flow in video tutorial.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | //Base Container final GridPane root = new GridPane(); //Positioning contents root.setHgap(15); root.setVgap(15); root.setAlignment(Pos.CENTER); //Creating User name fields final Label labelUserName = new Label("UserName:"); final TextField tfUserName = new TextField(); //Creating password fields final Label labelPassword = new Label("Password:"); final TextField tfPassword = new TextField(); //Creating button final Button btnOK = new Button("Click Me"); btnOK.setAlignment(Pos.BOTTOM_RIGHT); //Adding contents to the root root.add(labelUserName, 0, 0); root.add(tfUserName, 1, 0); root.add(labelPassword, 0, 1); root.add(tfPassword, 1, 1); root.add(btnOK, 1, 3); //Creating a window on which root will be displayed with provided width and height final Scene scene = new Scene(root, 400, 300); //Set scene to the stage primaryStage.setScene(scene); //Set app title primaryStage.setTitle("JavaFX Demo"); //Show/Launch the app primaryStage.show(); //Adding click listener to button btnOK.setOnAction(event -> System.out.println("Button clicked!")); |
This is a basic example of JavaFX. Hope this will be helpful to you.
Keep reading my blog and send me your suggestions. Thankx :)
Comments
Post a Comment
You are responsible person and please write responsibly