Trident part 1 – Hello world
June 21st, 2009 | 3 Comments »Over the course of the next few days i’m going to talk about different concepts in the Trident animation library for Java applications. Part one introduces the “Hello world” example.
Timeline is the most important concept in Trident. Here is a simple example that illustrates the basic timeline terms:
import org.pushingpixels.trident.Timeline; public class HelloWorld { private float value; public void setValue(float newValue) { System.out.println(this.value + " -- " + newValue); this.value = newValue; } public static void main(String[] args) { HelloWorld hello = new HelloWorld(); Timeline timeline = new Timeline(hello); timeline.addPropertyToInterpolate("value", 0.0f, 1.0f); timeline.play(); try { Thread.sleep(3000); } catch (Exception exc) { } } }
- We import the
org.pushingpixels.trident.Timelineclass. - We define a private float attribute of this class, and provide a public setter for this attribute.
- We create a new instance of our test class and a timeline associated with that instance.
- We specify that the
valueattribute of that instance should be interpolated from0.ofto1.0fwhen the timeline is played. - Finally, we play the timeline.
- The
Thread.sleep(3000)makes sure that the application waits long enough for the timeline to finish playing
Here is the output of this application:
0.0 -- 0.0 0.0 -- 0.436 0.436 -- 0.514 0.514 -- 0.594 0.594 -- 0.672 0.672 -- 0.75 0.75 -- 0.828 0.828 -- 0.906 0.906 -- 0.984 0.984 -- 1.0 1.0 -- 1.0
Note that the actual numbers depend on the current system load. The setter is called by the timeline at timeline pulses. A timeline pulse is the point where the timeline “wakes up” and changes the values of all registered fields. The values are changed based on how much time has passed since the timeline has started playing.
The three basic timeline concepts illustrated in this sample are:
- A timeline is associated with an object.
- A timeline interpolates values of object fields using the public setters of the relevant class.
- The field values are changed at timeline pulses.
Related posts:
- Trident 1.1 – custom pulse source Trident animation library for Java applications is nearing release 1.1 (code-named Bogeyman), and it’s time...
- Trident part 2 – interpolating fields Over the course of the next few days i’m going to talk about different concepts...
- Trident 1.1 – interpolating properties Trident animation library for Java applications is nearing release 1.1 (code-named Bogeyman), and it’s time...
- New in Trident 1.2 The Trident animation library was born in February 2009 out of the internal animation layer...
Beautiful API, I’m Java Developer and i begin with Java 2D and the customization of look and feel, i very appreciate your job. can you tell me if Trident is just a API?, if you want to include it in substance API or if you want to make a new suite of animation API.
Stanyslas – i will write about Trident plans in the next few days.
Thanks
Kirill
Trident is what i was looking for. Thanks!