JavaFX UbuntuClock

So I started playing with JavaFX in my spare time and found a nice simple example for a clock, I decided to spend some time, change it, finish it and improve it and here is what I created from it.

UbuntuClock

You will need Java 1.8.x installed

$ java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

This is how you would run the clock in the background.

$ nohup java -jar UbuntuClock.jar &

I have also included the dekstop file that you can copy to your autostart folder

$ cp ubuntufxclock.desktop ~/.config/autostart/

Here is a little code snip just for the taste


public void start(final Stage stage) throws Exception {
final Parent root = GroupBuilder
.create()
.children(clockDial(), UbuntuImage(), UbuntuTitle(), minutesMarks(), hourMarks(), hourHand(),
minuteHand(), secondsHand()).build();
setUpMouseForScaleAndMove(stage, root);
Scene scene = transparentScene(root);
showTransparentStage(stage, scene);
}

private Node UbuntuTitle() {
final HBox hbox = new HBox();
Label label = new Label("Ubuntu");
label.setTextFill(Color.WHITE);
label.setFont(Font.font ("Verdana", FontWeight.BOLD, FontPosture.ITALIC, 20));
hbox.setLayoutX(80);
hbox.setLayoutY(160);
hbox.getChildren().add((label));
return hbox ;
}

private Node UbuntuImage() {
final HBox box = new HBox();
Image image = new Image("/ubuntu-mini.png");
ImageView iv1 = new ImageView();
iv1.setImage(image);
box.setLayoutX(98);
box.setLayoutY(55);
box.getChildren().add(iv1);
return box;
}

Here are all the files you require to either compile it yourself or simply run it.

This TAR file contains the UbuntuClock.jar (Extract and execute)
This is the full source code for UbuntuClock (In JavaFX 1.8.25)
This TAR file contains the ubuntufxclock.desktop (Extract and save to autostart)

Enjoy it and any questions please feel free.

Leave a Reply