MY JAVAFX WATCH
MY JAVAFX WATCH
The root it’s an AnchorPane, the tricks I used were setting the stage to
transparent by calling
primaryStage.initStyle (StageStyle.TRANSPARENT) method and setting the scene fill to null, now only children nodes are visible.
I used the Calendar abstract class for time i.e.
Calendar cal=Calendar.getInstance ();
Int minute=cal.get (Calendar.MINUTES);
To check am/pm I used
a ternary operator: - String am_pm=cal.get(Calendar.AM_PM) == 1 ? "pm"
: "am"; if cal.get(Calendar.AM_PM) returns 1 am_pm=”pm”
;else am_pm=”am”;
All the labels need to
update after a period of time, like for the minute label needs to change after
every 60 seconds.
The Timer
I used the
AnimationTimer class like so
AnimationTimer timer=new AnimationTimer() {
public void handle(long now)
{
Calendar cal=Calendar.getInstance ();
Int minute=cal.get (Calendar.MINUTES);
Platform.runLater(()
-> {
label.setText(String.valueOf(minute));
});
} };
timer.start();
The Seconds
Simulation
I needed to simulate
seconds somehow, and I thought of FillTransition that’s transitioning from one
color to another by a specified duration, in our case one second transition
from Color.AQUA to Color.RED
FillTransition Code:-
FillTransition ft=new FillTransition();
ft.setFromValue(Color.AQUA);
ft.setToValue(Color.RED);
ft.setCycleCount(Timeline.INDEFINITE);
ft.setDelay(Duration.seconds(1));
ft.setShape(circle);
ft.play();
RESULTS
NB/:The fonts are from the Enzo library
Comments
Post a Comment