Introductory Programming In Java
| HW 1 |
HW 2 |
HW 3 |
HW 4 |
HW 5 |
HW 6 |
HW 7 |
Homework 6
Programming with JavaFX
JavaFX: Events and Effects Programming
Objectives
To start writing simple graphics and GUI programs to learn the basic of event-driven programming, and have a a first experience of JavaFX RIA framework.
Note 1
Read parts of the Oracle JavaFX tutorial to help your self with this lab exercises.
Note 2
Define all programs be part of the module lab6.
Exercise One: a simple JavaFX program with shapes
Using the Eclipse IDE (or Netbeans, or IntelliJ IDEA), create
a JavaFX program called ColouredShapes.java,
which displays a few simple shapes like square,
triangle, circle and so on, all having different colours.
Then (after succeeding in the previous step) attach an event handler
to each of the shape to detect events when the mouse moves into
the region occupied by the shape. By using the original Assignment Two
code as example, you will have to set
onMouseMovedProperty of a shape object to an
EventHandler〈MouseEvent〉 and implement
the handle(MouseEvent e) method to generate a desired effect
when the mouse enters the shape region. Consider the following
effects:
- printing mouse coordinates to
stdout - changing the shape colour while the mouse is in and changing the colour back when it's out
Exercise Two: adding transition effects
Create another program, called SimpleTransitions.java.
which displays a simple shape with colour and then does one of the following
when an event is genrated:
- moves to another location (choose yourself which direction and how far) and stay there when you perform a mouse click inside it
- rotates by 45° clockwise when you press the key "UP", and by 45° counterclockwise when you press "DOWN"
- (optional) morphs into a different shape object when click the mouse outside the original shape. Make the shape changing lasts 3 or 5 seconds.
When (if) all of the above transition effects work as described, try to combine them so a transition involves movement (shift and rotation), shape and colour changes. I leave it to you to choose the actual combination and the event which triggers the transition: It can be a mouse event, or a keyboard event, or you can add a button which will trigger the transition when clicked.
Exercise Three (optional): Model and View
Create two classes, View.java (which is a
javafx.applicationApplication class, like the above
it contains the main-launch-start methods) and Model.java
class (which is an ordinary Java class defining the data). Choose Model to represent
a collection of circles of different radii, locations and colours. These must be
logical shapes (like abstract geometrical objects), not graphical primitives which JavaFX
displays (examples of which we've seen in Ex. 2). Then make the View to create the Model
object (called model), read its data which describe the shapes and
then generate graphical shapes according to their description in the
model object. Finally, extend the Model to allow the colour to take one
of the several values (use private array field Color[] colours
to choose from) when model object is created. Then, when the model is
displayed in the View, mouse clicks inside any of the circles result in the colour change
such that a sequence of successive clicks allow to change the circle colour several times
utilising the full gamut.
Assessment
You will get up to two marks, if you submit your work by 14 May, 2013,
to the Mercurial repository following the instructions provided
in the Lab 6. Instead of using ass2
for you working directory, you should use the name
homework6.
| HW 1 |
HW 2 |
HW 3 |
HW 4 |
HW 5 |
HW 6 |
HW 7 |
