
Quick Contact
Java Tutorial
- What is Java?
- History of Java
- Hello Java Program
- Features of Java
- Basic Syntax
- Java Setup
- Data Types in Java
- Java Variables
- Operators in Java
- JVM
- Java If-else Statement
- Switch Case Statement
- Java Loops
- Do-While Loop
- Java While Loop
- Continue Statement
- Break Statement in Java
- Constructors in Java
- Oops Concept in Java
- Features of OOPs
- Inheritance
- Exeception handeling
- Aggregation (HAS-A relationship) in Java
- Method Overriding in Java
- Method Overloading
- Java Static Keyword
- Java This Keyword
- Java Final Keyword
- Polymorphism
- Static Binding and Dynamic Binding
- Abstract class in Java
- Access Modifiers in Java
- Difference between abstract class and interface
- Interface in Java
- Garbage Collection in Java
- Java Package
- Encapsulation
- Serialization and Deserialization in Java
- Java Inner Classes
- Java Applets
- Multithreading in Java
- Thread Priorities in Java
- Thread Creation
- Inter Thread Communication
- Wrapper Classes in Java
- Java Input Output
- Java AWT Introduction
- Java Layout Manager
- Java Layout Policy
- Java AWT Events
- Collection Framework
- Collection Framework List Interface
- Swing in Java
- Swing Utility Classes
- Swing Layout Managers
- Java JDBC
- Hibernate Framework Overview – Architecture and Basics
Springboot
- Spring Environment Setup
- Spring Boot CRUD REST API Project using IntelliJ IDEA | Postman | MySQL
- Dockerizing Spring Boot Application | Spring Boot Docker Tutorial
- spring-boot-restapidocumentation with swagger
- Spring Boot HttpClient Overview
- Apache HttpClient POST HTTP Request Example
- Apache HttpClient PUT HTTP Request Example
- Apache HttpClient DELETE HTTP Request Example
- Apache HttpClient HTML Form POST Request Example
- Spring Boot JSP Exampl
- Deploying Spring Boot WAR file with JSP to Tomcat
- Spring Boot Annotations
- Spring Core Annotations
- Spring MVC Annotations with Examples
- Spring Scheduling Annotations
- Spring - Java-based Container Configuration
- Spring Java Based Configuration Example
Hibernate
- Hibernate 5 hello world
- Hibernate- One to One Unidirectional Mapping Annotation Example
- Hibernate - Batch Processing
- Hibernate - Interceptors
- Hibernate 5 - Create, Read, Update and Delete (CRUD) Operations Example
- Hibernate Transaction Management
- Hibernate One to Many Unidirectional Mapping Example
- Hibernate One to Many Bidirectional Mapping Example
- Hibernate Many to Many Annotation Mapping Example
- Hibernate Primary KeyJoin Column
- Hibernate First Level Cache with Example
- Hibernate XML Configuration Example with Maven + Eclipse + MySQL Database
- Hibernate Java Configuration Example
- JPA 2 with Hibernate 5 Bootstrapping Example
- JPA and Hibernate Cascade Types
- Hibernate/JPA - Primary Key Generation
- Hibernate 5 - Enum Type Mapping Example
- Hibernate Component Mapping
- Hibernate Object States – Transient,Persistent and Detached
- Hibernate 5 - Save an Entity Example
- Hibernate 5 - Persist an Entity Example
- Hibernate 5 - saveOrUpdate() Method Example
- Hibernate 5 - get(), load() and byId() Method Examples
- Hibernate 5 - merge() Example
- Hibernate 5 - Delete or Remove an Entity Example
- Hibernate 5 - load() Method Example
- Hibernate Session Interface Methods
- Hibernate Session.clear() Method Example
- Introduction Of Java strutes to Architecture
- Struts 2 - Architecture
- Struts 2 - Configuration Files
- Struts 2 - Actions
- Struts 2 - Interceptors
- Struts 2 - Results & Result Types
- Struts 2 - Value Stack/OGNL
- Struts 2 - File Uploading
- Struts 2 - Database Access
- Struts 2 - Validations Framework
JAVA FX
- JavaFX Tutorial
- Introduction to JavaFX Pane
- JavaFX Popup
- JavaFX group
- JavaFX Controller
- JavaFX Gradient Color
- JavaFXAnchorPane
- JavaFXTabPane
- JavaFX Scene
- JavaFX Stage
- JavaFXWebView
- JavaFX Timeline
- JavaFX Timer
- JavaFX Image
- JavaFX Background
- JavaFX dialog
- JavaFX Font
- JavaFXTextArea
- JavaFXObservableList
- JavaFX GUI
- JavaFX FXML
- JavaFXEventHandler
- JavaFXGradle
- JavafxScrollpane
- JavaFXAPI
JavaFX Scene
JavaFX Scene is class. Scene object can be said it as the root of JavaFX scene graph. This class contains all the visual GUI components within it. This class is available in scene.Scene package. If we want to make use of it by importing this package. If JavaFX Stage window visible when we set scene object to stage object. We can attach only one scene object to one stage at a time. If we try to attach an already attached scene to another stage then it is first detached from the previous stage (1st attached stage). Same way we can attach only one stage object to one scene at a time.
Advantage:
- Used to add any JavaFX element.
Frequently Used Constructors:
-
Scene(Parent root):
Creates a Scene object by new keyword with JavaFX element as argument.
-
Scene(Parent root, double width, double height):
Creates a Scene object by new keyword with JavaFX element, width and height as arguments.
-
Scene(Parent root, double width, double height, Paint fill):
Creates a Scene object by new keyword with JavaFX element, width, height and color as arguments.
Frequently used Methods:
-
show():
The show() method will show the output.
-
setScene(scene):
This method set the Scene object.
-
setTitle():
The setTitle() the set the title of the application.
How does Scene Work in JavaFX?
- Accessing JavaFX features user defined class must extends Application
- In JavaFX creating any JavaFX element is first step. ImageView, AnchorePane, ScrollPane, MenuBar etc. This can instantiate by using new.
Syntax #1:
ImageViewimageView=new ImageView(); ScrollPanescrollPane=new ScrollPane(); AnchorPaneanchorPaneRef=new AnchorPane (); . . Etc.
- Create VBox or any other display(like TilePane or HBox as per requirement) class to add the items is second step.
- Third step is creating scene for apply show method on to it.
- Fifth step is showing output to the end user by applying show () method on the scene object.
Syntax #2:
VBoxvBox=new VBox (scrollPane or ImageView ,anchorPaneRef etc.); //Gives vertical box
Syntax #3:
Scene screen = new Scene(vBox, length, width);
Adding Scene reference screen to the Stage object reference is fourth step. Adding output screen to Stage. We will get this stage object reference from start predefined JavaFX method.
Syntax #4:
stage.setScene(screen);
Syntax #5:
stage.show();
Examples
Example #1 – Scene with Circle
Code:
package com.scene; import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.Group; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.scene.text.Text; import javafx.scene.text.Font; public class SceneDemo extends Application { @Override public void start(Stage outputStage) { //settings title to the scene application outputStage.setTitle("Scene Demo with width=500 and height=350"); //creating a group object for adding any element Group groupObject = new Group(); //creating scene object for adding group object Scene sceneObject = new Scene(groupObject,500,350); //setting scene color sceneObject.setFill(Color.LIGHTGRAY); //creating circle object for display on window Circle sceneCircle = new Circle(100, 60, 40, Color.DARKORANGE); //creating a text displayed on the window Text sceneText = new Text(50, 120, "Scene Demo with Circle"); sceneText.setFill(Color.GREEN); //creating font object for set the font FontsceneFont = new Font(23); sceneText.setFont(sceneFont); // adding all the created elements one by one groupObject.getChildren().add(sceneText); groupObject.getChildren().add(sceneCircle); outputStage.setScene(sceneObject); outputStage.show(); } public static void main(String[] args) { //JVM calls start method automatically Application.launch(args); } }
Example #2 – Scene Login Page
Code:
package com.scene; import javafx.application.Application; import javafx.geometry.HPos; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; import javafx.scene.layout.BorderPane; import javafx.scene.layout.ColumnConstraints; import javafx.scene.layout.FlowPane; import javafx.scene.layout.GridPane; import javafx.scene.layout.Priority; import javafx.scene.paint.Color; import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.stage.Stage; public class SceneLogin extends Application { @Override public void start(Stage outputStage) { // setting the title outputStage.setTitle("Login Page with Width=400 and Height=200 and Color=blue"); // creating border pane for adding login elements BorderPaneborderPaneRef = new BorderPane(); Scene loginScene = new Scene(borderPaneRef, 600, 200, Color.BLUE); // creating grid pane to set the elements at specific location GridPanegridpaneRef = new GridPane(); gridpaneRef.setPadding(new Insets(5)); gridpaneRef.setHgap(5); gridpaneRef.setVgap(5); // creating column constraints ColumnConstraintsfirstColumnConstraint = new ColumnConstraints(100); ColumnConstraintssecondColumnConstraint = new ColumnConstraints(50, 150, 300); secondColumnConstraint.setHgrow(Priority.ALWAYS); gridpaneRef.getColumnConstraints().addAll(firstColumnConstraint, secondColumnConstraint); // creating mail id label LabelmailIDLabel = new Label("Mail ID: "); // creating password label LabelpasswordLabel = new Label("Password: "); // creating text fields for mail and password TextFieldmailIDField = new TextField(); PasswordFieldpasswordField = new PasswordField(); // creating button for Login Button saveButton = new Button("Login"); // setting the grids of label and fields in Horizontal positions like // left and right GridPane.setHalignment(mailIDLabel, HPos.RIGHT); GridPane.setHalignment(passwordLabel, HPos.RIGHT); GridPane.setHalignment(mailIDField, HPos.LEFT); GridPane.setHalignment(passwordField, HPos.LEFT); GridPane.setHalignment(saveButton, HPos.RIGHT); // adding labels and fields gridpaneRef.add(mailIDLabel, 0, 0); gridpaneRef.add(mailIDField, 1, 0); gridpaneRef.add(passwordLabel, 0, 1); gridpaneRef.add(passwordField, 1, 1); gridpaneRef.add(saveButton, 1, 2); // creating flow pane FlowPanetopBanner = new FlowPane(); topBanner.setPrefHeight(40); // creating font Font serif = Font.font("Times New Roman", 30); // creating text TextcontactText = new Text("Login Page"); contactText.setFill(Color.BLACK); contactText.setFont(serif); // adding elements topBanner.getChildren().addAll(contactText); borderPaneRef.setTop(topBanner); borderPaneRef.setCenter(gridpaneRef); outputStage.setScene(loginScene); // displaying output outputStage.show(); } public static void main(String[] args) { //JVM calls start method automatically launch(args); } }
Example #3 – Scene Cursor
Code:
package com.scene; import javafx.application.Application; import javafx.scene.Cursor; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.layout.TilePane; import javafx.stage.Stage; public class ScenLine extends Application { // launch the application @Override public void start(Stage outputStage) { // setting the title outputStage.setTitle("Scen Cursor Demor"); // creating tile pane object TilePanetilepane = new TilePane(); // creating label object Label label = new Label( "\n\n\n\n\t\t\t Wait Cursor Demo. When we hover the cursor on to the text then waiting icon displayed"); // adding label to tile pane tilepane.getChildren().add(label); // creating scene with width and height Scene scene = new Scene(tilepane, 600, 150); // different cursor styles // you can uncomment each style and see the difference scene.setCursor(Cursor.WAIT); // scene.setCursor(Cursor.CROSSHAIR); // scene.setCursor(Cursor.DISAPPEAR); // scene.setCursor(Cursor.MOVE); // scene.setCursor(Cursor.CLOSED_HAND); // setting the scene outputStage.setScene(scene); // displaying the output outputStage.show(); } public static void main(String args[]) { // JVM calls start method directly launch(args); } }
Apply now for Advanced Java Training Course