Well, I think that to have a well defined goal is always a nice start. I can stay focus on it and my reflections keep together in the good direction.
If as me you prefer sometimes to have a preview of the result before read the next, just click on the launch button!
Draw the rectangle
So to start I had to draw a simple rectangle; quite easy with JavaFx:Rectangle{
width: 120
height: 100
fill: Color.BLACK;
}
LinearGradient{
startX: 0.0
startY: 0.0
endX: 0.0
endY: 1.0
stops : [
Stop{offset: 0.0 color: Color.rgb(163,163,163)},
Stop{offset: 0.5 color: Color.rgb(106,106,106)},
Stop{offset: 0.51 color: Color.rgb(43,43,43)},
Stop{offset: 1.0 color: Color.rgb(57,57,57)}
]
}
This code can now replace the Color.BLACK in our previous rectangle's code. Actually we have the rectangle with the right color. After having done the same thing to have the rectangle with blue tints, we just have to start the animating stuff. Before going on I'd like to precise that the 2nd rectangle is located at the same location than the 1st rectangle but with an opacitiy value of 0. We will only change the opacity to create the fading animation.
Fade animation
Have you already developed a Swing application? If so, did you ever try to add animation stuff to it? I don't know about you, but to me it has always been a nightmare. The good news are that with JavaFX, a new era is here!For my demo, I have been really keen about the JavaFX abilities, here is the code to get a fade animation on our rectangle:
Timeline{
keyframes:[time: 0.6s values: op => 1.0 tween Interpolator.LINEAR]
}
JavaFX Custom node
The last thing to do is drawing the text of the menu item. Once again, quite easy:Text{
label: "HOME"
x: 0
y: 0
fill: Color.ORANGE
}
That's it for the 1st step. We have seen how to create a JavaFX custom node that is reusable. But there are still serveral steps from the final deezer's clone... Watch out!
[The code source is avaible under BSD license.]


0 comments:
Post a Comment