Description
Write a JavaFX program that will open and display an image file. The class with the main method of the program
should be called JIMachine.
The program will have five buttons:
Open— Display a file dialog box that lets the user select an image file.
Zoom In— Make the image display size 25% larger. The zoom should be cumulative, so that pressing the
button twice will make the image larger than it was after pressing the button only once. (Don’t change the
bitmap itself to zoom in, just change the way it’s displayed.)
100%— Display the image at its original size.
Zoom Out— Make the image display size 25% smaller. As for zoom in, the zoom should be cumulative.
Quit— Exit the program.
You’ll probably want to use a BorderPane and put the image in the middle with the buttons in a pane on one of
the edges.
Note that you will need a pointer to the stage to use a FileChooser dialog box with JavaFX. Also, you can pass
the File reference you get from the FileChooser to the Image constructor like this:
new Image(file.toURI().toURL().toExternalForm());
Otherwise you will run into problems if you pass an absolute path to the Image constructor.
JavaFX
You will need to download and install JavaFX 11. It’s available from openjfx.io where you can download the
library and read installation instructions.
Please test your program from the command line even if you use an IDE to write your program. The OpenJFX
page includes instructions for using compiling and running JavaFX programs from the command line. You might
find a shell script (Linux/macOS) or batch file (Windows) helpful for running your program.
The online API documentation for JavaFX 11 is at https://openjfx.io/javadoc/11/ The modules we will be using
the most are graphics and controls.
Turn in
Make sure that your class(es) are not in a package and that the class with the program’s main method is named
JIMachine. Put your source file(s) into a zip file and turn in the zip file on Canvas. Your files should not be
inside a folder in the zip file, and there should not be any files other than source files, an optional README.txt
file, and a few small test images (if you’d like).
Points
15 Open button displays dialog box
30 Image appears on screen
15 Zoom in
15 100% button
15 Zoom out
10 Quit
100 TOTAL