1. Theory and slides on JavaFX Bindings.

There is a good tutorial about javafx bindings on the oracle website.

The slide set gives a summary of that.

2. Exercises week 7, Java FX Bindings

2.1. FX Clock

This exercise is about bindings and a bit about a JavaFX toy clock.

  1. ticker helper

  2. the java fx clock

You will also learn how to combine maven projects into one final result.

You should build the projects in order.

The toy clock will look like the thing in the picture.

Figure 1. BB8 as a clock face

You’ll program a clock like this, including all its functionality and both the digital as well as the analog display, step by step.

The clock’s operation mimics a mechanical clock, driven by a synchronous electric motor, which drives the right hand time element which in turn drives the element on its left and so on.

2.1.1. Tasks

Start by answering the questions below in a README.md file inside the maven project, at the same level as the pom.xml file.

You can also take notes there, to keep things in one place.

  1. What are functions available in this design?

    1. Think of display(s), buttons and what time means.

    2. Describe these functions.

    3. Is there any interaction between the elements in the display?

  2. Describe how you would thoroughly test this device.

The project has two maven projects: TickerHelper and the fxclockstart.

Build the javadoc of the TickerHelper library and study it to see how it can be used.

  • Complete the unit tests in TimeElementTest to test your time-element implementation.

  • Add seconds and days: Make sure that your clock registers days, hours, minutes and seconds too.

  • Consider your implementation and check if it is DRY (*D*on’t *R*epeat *Y*ourselves).

Note to use the fx- profile when building and running the fxclock project.

time element objectdiagram
Figure 2. time element object diagram
timeelement classdiagram
Figure 3. time element class diagram

2.1.2. JavaDoc

The javadoc of ticker helper and the of the application fxclock javadoc and fxclock test javadoc are available by following the links.

2.1.3. Corrections to the start project code

Due to the way the FXMLLoader works, having incorrect or incomplete code in the controller class will throw exceptions that are not very helpful to say the least.

That the students experience this problem has to do with the fact that we make the code incomplete on purpose, to give you some work :-).
However, our quality checks where not properly in place, so there you have it.

To avoid this problem,

  • you can comment out some of the given code (which IS needed for the complete solution)

  • and re-enable (uncomment) it once your controller is complete and has its fields both declared and properly initialised.

Code to temporarily comment out:

comment in method clockWork
  private void clockWork() {
//      second.increment();
comment in method setupAlarm
 private void setupAlarm() {
        ahourLabel.opacityProperty().bind( alarmOpacity );
        aminuteLabel.opacityProperty().bind( alarmOpacity );
        ahourSep.opacityProperty().bind( alarmOpacity );
////// comment to make it work with missing field initialisations
//      setPerspective();
//      alarmTimeReached = ahour.valueProperty()
//            .isEqualTo( hour.valueProperty() ).and( aminute.valueProperty()
//            .isEqualTo( minute.valueProperty() ) );
//       alarmTimeReached.addListener( this::soundAlarm );

2.2. FX Triangulation

Use java fx binding to show the changing values of side lengths and area of a triangle.

A triangle is determined by three points, A, B, C. The sides are called a,b, and c, where a is opposite point a etc.

The length of a side is determined by the formula of Pythagoras.

Let \(A_x,A_y\) be the coordinates for point \(A\), similar for \(B\) and \(C\).

The length \(a\) of the side opposite \(A\): \( a= \sqrt{(C_x-B_x)\cdot(C_x-B_x)+(C_y-B_y)\cdot(C_y-B_y)}\).

With this we can also compute side lengths \(b\) and \(c\).

With lengths a, b, and c the area of a triangle can be determined with Heron’s formula.

Let \(s = \frac{a+b+c}{2}\)

Then the area of the triangle is \(\text{Area}= \sqrt{s\cdot(s-a)\cdot(s-b)\cdot(s-c)}\).

The javadoc of the application and the test javadoc are available by following the links.

Figure 4. screenshot of app