Lab 7: Shapes Revisited




In this assignment you will revist the work you did for Lab 4. In particular, you will write your own code to create a WinPlotterFX1 instance and draw shapes in the window. The characteristics of the window and the shapes to be drawn must be read from a file.


Shape Class Upgrades

First, you must revisit each of the classes implemented for lab 4: Shape, Triangle, LabeledTriangle, Rectangle, LabeledRectangle, and Circle. You should incorporate any feedback you received from your instructor and add checks to the constructors to ensure that no shape is created with unrealistic dimensions. In particular, if a non-positive value is passed to a constructor for one of the dimensions (width, height, base, radius), an IllegalArgumentException with an appropriate message must be thrown.

You must also implement the Point class described in lab 4.

FaceMaker Replacement

You must implement a ShapeLoaderApp class to replace the FaceMaker class you developed in Lab 4. Your implementation must read a file that contains information about the picture, create a window, and then draw all of the specified shapes on the window. The program must ask the user to select a file; however, you may determine how you obtain the file location from the user. An example file is shown below:

Demonstration Picture
800 600
P: 40 40 #000000
C: 40 40 #FF0000 30
T: 60 60 #00FF00 100 50
R: 160 160 #0000FF 50 150
LT: 360 360 #00FF00 100 50 Tri
LR: 460 460 #0000FF 150 100 Reck Tangle Angle Rangle
Figure 1: Sample input file

Sampe Results

Figure 2: Picture generated by the example in Figure 1

The file has the following format:

The shape formats are specified as:


Your ShapeLoaderApp must extend Application and instantiate a WinPlotterFX1 object, which extends Stage. The ShapeLoaderApp must implement the following methods:

Instance methods

Class methods

Handling Exceptions

There are a number of situations that could cause your program to throw an exception. For example, if the file is not found, can't be opened, or contains incorrectly formatted data. If the program is unable to correctly read the picture header information (the first three lines) from the file, the program should display an appropriate Alert dialog. The program should then end. If an error is encountered while reading a line of the file after the header information, a useful error message should be written to the console and the program should continue on to the next line in the file.

You should experiment with a number of input files containing invalid formatting. Without doing this it is unlikely that your code will handle all of the possible ways that things could go wrong.

1Just for Fun

You may choose to make use of the WinPlotterFX class to do your drawing or implement your own GUI to draw the shapes.


This laboratory assignment was developed by Dr. Chris Taylor.

See your professor's instructions for details on submission guidelines and due dates.