Lab 1
Get started now
## Objectives * Demonstrate competency in many prerequisite areas including: * Graphical User Interfaces with JavaFX * Text file input * Handle exceptions in a robust and meaningful fashion ## Overview In this assignment you will begin developing a dot-to-dot generator program. The subsequent two laboratory assignments will build on this one, allowing you to improve your initial submission based on feedback from your instructor and expand the program's functionality. ## Assignment You must create a program that will read a picture from a `.dot` file and graphically display the picture stored in the file. <figure>[![User Interface](lab1.png)](lab1.png)<figcaption>Figure 1: User Interface</figcaption></figure> Your program must have two menus each with two menu items: * **File** * **Open** &mdash; Loads a `.dot` file and displays the dots in the file and connects neighboring dots with lines. * **Close** &mdash; Exits the program (use `Platform.exit()`). * **Draw** * **Lines Only** &mdash; Redraws the loaded picture drawing only lines (no dots). * **Dots Only** &mdash; Redraws the loaded picture drawing only dots (no lines). The **Draw** menu items should only be active when a picture has been loaded. You may use FXML but are not required to do so. ## Details ### Class Structure All of your classes should be placed in a package whose name matches your MSOE username. You must implement two classes: * **`Dot`** &mdash; Represents a dot in the picture. * **`Picture`** &mdash; Holds a list of `Dot`s that describe a picture. The `Picture` class must implement the following methods: * **`void load(File file)`** &mdash; Loads all of the dots from a `.dot` file. * **`void drawDots(Canvas canvas)`** &mdash; Draws each dot in the picture onto the canvas. * **`void drawLines(Canvas canvas)`** &mdash; Draws lines between all neighboring dots in the picture on the canvas. ### `.dot` File Format Your program must be able to read dot files that contain a list of dots. The file is formatted such that each dot is on a separate line. A dot consists of a horizontal and vertical component separated by a comma. Each component is a floating point value between zero and one. For example, `square.dot` looks like this: <pre> 0.1, 0.1 0.1, 0.9 0.9, 0.9 0.9, 0.1 </pre> Here are a few sample .dot files: [circle.dot](circle.dot), [balloon100.dot](balloon100.dot), and [magician.dot](magician.dot). If you'd like to make your own graphic files, you can use the [GraphicFileGenerator.jar](GraphicFileGenerator.jar). The program begins with a file chooser dialog that can be used to select a background image (which you can then trace). Hit cancel if you'd rather just have a black background. To draw, press and hold the mouse down. When you're done, release the mouse. You'll then need to save the points to a file (use the menu). ### Drawing Dots A dot can be drawn on a `Canvas` by first obtaining the `GraphicsContext` and then calling the `fillOval()` method. Be sure to set an appropriate fill color and center the dot over its coordinate location. ### Drawing Lines Lines should be drawn between all neighboring dots, including a line from the last dot back to the first dot. The lines can be drawn on a `Canvas` by first obtaining the `GraphicsContext` and then creating a path. To do this: 1. Call `beginPath()` 1. Move to the location of the first dot by calling `moveTo()` 1. Draw a line to the next dot by calling `lineTo()` 1. Repeat the previous step for all dots 1. Call `closePath()` 1. Call `stroke()` to draw the path ### Exception Handling There are a number of situations that could cause your program to throw an exception. For example, if the file is not found, cannot be opened, or contains incorrectly formatted data, it is likely that an exception will be thrown. In these cases, the program should display an useful message and log the error. Your program should write to the log file `d2d.txt`. ## Just For Fun Ambitious students may wish to: * Try replacing `lineTo()` with `quadraticCurveTo()` or `bezierCurveTo()`. * Add number annotations next to each dot. * Create a print to PDF option. ## Lab Deliverables > See your professor's instructions for details on submission guidelines and due dates. > * Dr. Taylor's students: See below > * All other students should refer to Blackboard > >If you have any questions, consult your instructor. ## Acknowledgment This laboratory assignment was developed by [Dr. Chris Taylor](/taylor/).

Tuesday, 14-Mar-2017 13:03:39 CDT