
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 Timeline
Timeline in JavaFX is basically used to define free and flexible forms of animation. Timeline in JavaFX works on using the keyframes processing each of the keyframes individually and sequentially. It does not guarantee the timing of processing of each keyframe; instead it processes each keyframe at a specified time interval. Programmers have the facility to add the keyframes to the timeline either at the time of creation or afterwards. Timeline is a subclass of javafx.animation.Animation class. A lot of other things can be performed using timeline like setting the reverse of timeline, loop of how many times it should run, etc.
Syntax:
Below given is the basic syntax of using the Timeline in JavaFX:
Final Timeline tm = new Timeline(); tm.add(new KeyFrame(Duration.millis(10000), new KeyValue (button.translateXProperty(), 8))); tm. setCycleCount(8); . .. ..
How does the JavaFx Timeline Function Work?
Some of the important points defining the working of JavaFX timeline are given below:
- Timeline in JavaFX is nothing but an animation consisting of many KeyFrameobjects , each of which needs to be run sequentially.
- Some of the standard attributes of Timeline are auto- reverse and cycle count.
- Cycle count is nothing but the count of the number of times, an animation should be played. We can also play the animation infinite times using Timeline.INDEFINITE. But by default animation runs only 1 time.
- Auto- reverse is nothing but a boolean value to indicate whether the animation can play backwards or not.
- In order to set the largest time of the Timeline, KeyFrameAnimation.cycleDurationProperty() is used.
- We can not change the keyFrames of the running timeline. In order to use the new value, one needs to stop and start it again.
- In the timeline of JavaFX, cycle count is 1 and the auto-reverse feature is set to TRUE.
- Method start() contains the main logic of timeline animation.
Constructors
Below given are the constructors of the Timeline in JavaFX:
S.No. | Constructor | Description |
---|---|---|
1. | Timeline() | It is a constructor of timeline having no parameters |
2. | Timeline(double targetFramerate, Keyframe… keyframe) | It is the constructor of timeline having 2 parameters, i.e. targetFramerate and keyFrames.It allows to define the custom Frame rate and keyFrames of the timeline. |
3. | Timeline(double targetFramerate) | It is the constructor of timeline having targetFramerate as its parameter. In this constructor, one needs to define the Animation.targetFramerate. |
4. | Timeline(Keyframe … keyframes) | It is the constructor of timeline having keyFrames as its parameter. There can be one or multiple keyFrames. |
Methods:
Below given are the methods along with their description used in the timeline of JavaFX:
S.no. | Method name | Method description |
---|---|---|
1. | getKeyFrames() | This method returns the keyframes of the respective timeline.
Syntax:public final ObservableList< keyFrame>getKeyFrames(); |
2. | stop() | As the name indicates, this method stops the animation and allows the head to start from the initial position. As using the stop() method is an asynchronous call so it might not get stopped immediately. If the animation is not working/ running, this method has no impact. It has ‘void’ as a modifier.
Syntax:public void stop() |
Some of the methods inherited from the javaFX.animation.Animation class are given below:
S.No. | Method name | Description |
---|---|---|
1. | getTargetframeRate() | This method defines the frame rate at which the animations should run, i.e. the frames per second. |
2. | getStatus() | This method is used to get the status of the Animation. Animation in JavaFX has basically 3 status, i.e. STOPPED, PAUSED and RUNNING |
3. | setStatus() | This method is used to set the status of property, i.e. an animation. Status can be set as STOPPED, PAUSED and RUNNING. |
4. | setCycleDuration() | This method is used to set the value of cycle duration. It is basically used to indicate the duration of Animation’s one cycle. It is a read only variable. |
5. | getCurrentTime() | This method is used to get the current time of the animation. Its default value is 0 ms. |
6. | setDelay() | This method is used to set the delay property of the animation. Using this, programmers can delay the start of the animation. By default, its value is 0 ms. |
7. | getDelay() | This method is used to get the delay of the animation. By default, its value is set to 0 ms. |
Example of JavaFX Timeline
Some of the examples implementing the usage of Timeline in JavaFX code are given below:
Example #1
Code:
import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.Timeline; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.VBox; import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.stage.Stage; import javafx.util.Duration; public class TimelineFX extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) { // Create the Text using text object Text text = new Text("Hello Hello!"); VBox root = new VBox(text); // Setting the text font size text.setFont(Font.font(12)); // Creating the Scene using its object Scene scene = new Scene(root); // Adding the Scene to the Stage stage.setScene(scene); // Now Setting the title of the above Stage stage.setTitle("This is stage title"); // Displaying the Stage using the show() method stage.show(); // Getting the Scene width and the Text width double sw = scene.getWidth(); double tw = text.getLayoutBounds().getWidth(); // Defining the Durations of animations Duration startD = Duration.ZERO; Duration endD = Duration.seconds(50); //Creating the keyFrames to use in timeline KeyValuestartValue = new KeyValue(text.translateXProperty(), sw); KeyFramestartFrame = new KeyFrame(startD, startValue); KeyValueendValue = new KeyValue(text.translateXProperty(), -6.0 * tw); KeyFrameendFrame = new KeyFrame(endD, endValue); // Creating a Timeline using above values Timeline t1 = new Timeline(startFrame, endFrame); // Setting the cycle count of animation t1.setCycleCount(t1.INDEFINITE); //Setting the auto reverse property of animation t1.setAutoReverse(false); // Running the animation using play() method t1.play(); } }
Apply now for Advanced Java Training Course