Lab 6
Get started now
## Objectives * Properly handle exceptions generated by an external class. * Construct software which uses an FXML layout file. * Implement `ActionEvent` listeners to detect events in text entry boxes. * Interpret Javadoc to make effective use of unfamiliar classes. * Integrate `Alert` and `TextInputDialog` classes into the handling of exceptions. ## Resources * [`WebsiteTester` Documentation](WebsiteTester.html) * [`lab6.jar`](lab6.jar) ## Assignment The web can be a wonderful place. We've all used a web browser to do useful things. But what is a web browser in reality? A web browser is a software application that downloads and renders files. Some files are text. Some files are binary. Some files have specific meaning such as images. But, all in all, the web just consists of a bunch of files that are accessed using a web protocol. In future classes you will learn more of the details of the web protocol. In this assignment you will build a system which will allow you to monitor material on the web. You must create a desktop application using JavaFX that looks similar to the GUI shown below. <figure>[![Desktop GUI](lab6b.png)](lab6b.png)<figcaption>Desktop GUI</figcaption></figure> Specifically, this application will: 1. Allow the user to enter a URL 1. Allow the user to enter the length of time to wait for a response (timeout) 1. Download the content of the specified URL 1. Display the filesize 1. Display the time it took to download the material 1. Display which port the download is using 1. Display the name of the host The user should only be able to edit the URL and Timeout text fields. Your solution must consist of a `Lab6` class that loads the FXML file and launches the app, a `lab6.fxml` file that describes the GUI layout, and a `Lab6Controller` class that responds to the UI elements specified in the FXML file. The `Lab6Controller` class must have two methods named `analyze()` and `setTimeout()` that handle events caused by pressing enter in the text fields or pressing the buttons. ## `WebsiteTester` Class You are to make use of `WebsiteTester` ([Javadoc](WebsiteTester.html)) class. This class is prebuilt and provided in the [`lab6.jar`](lab6.jar) file. This class connects with the web server and analyzes the connection. ## Operation Operation of the program begins with the user starting the program. The program will start with `http://msoe.us/taylor/cs1021/Lab6` as the default URL. The timeout will be set to the default value from the `WebsiteTester` class. The size, port, download time, and host entries will be blank, as well as the text area containing the text from the website. The user can then enter different text into the URL text field or enter a different value into the timeout text field. When the user clicks on either button, an event handler will interact with the `WebsiteTester` instance to produce the appropriate result. Pressing enter in the URL text field is equivalent to clicking the **Analyze** button, and pressing enter in the timeout text field is equivalent to clicking the **Set** button. The sequence diagram below shows exactly what needs to be done to respond to each event. <figure>[![Sequence Diagram](lab6a.png)](lab6a.png)<figcaption>Sequence Diagram for `setTimeout()`</figcaption></figure> <figure>[![Sequence Diagram](lab6c.png)](lab6c.png)<figcaption>Sequence Diagram for `analyze()`</figcaption></figure> ## Exception Handling ### Invalid Timeout If the timeout is invalid when an attempt is made to set the timeout, a message dialog box is displayed indicating that an invalid timeout has been entered by the user. When the message dialog closes, the text in the text field is reverted to the timeout present in the `WebsiteTester` object. ### Analyze Error When the user clicks on **Analyze**, there is the potential for several errors to occur. First and foremost, there is the possibility that the URL is Malformed. If this is the case, a text entry indicating that the text in the box is invalid is displayed and the url text field is set to a blank entry. If there is a socket timeout exception, a confirmation dialog is displayed indicating that the connection has timed out and asking if they would like to temporarily extend the timeout. If they choose to extend the timeout, then an input dialog is displayed allowing the user to select a temporary timeout. Once entered, the web request should be repeated using the desired temporary timeout. If the host cannot be found, a message is displayed indicating that the user has attempted to reach a host which does not exist. If a general IO error occurs, a message is shown indicating that there was a problem reading from the given file. The program must use [`Alert`](http://javadoc.taylorial.com/javafx.controls/scene/control/Alert.html) and [`TextInputDialog`](http://javadoc.taylorial.com/javafx.controls/scene/control/TextInputDialog.html) dialogs when responding to errors (see [examples](http://code.makery.ch/blog/javafx-dialogs-official/)). ### Sample Error Dialogs <figure>[![Error dialog when URL field is blank](lab6e1.png)](lab6e1.png)<figcaption>Error dialog when URL field is blank</figcaption></figure> <figure>[![Error dialog when URL field http://www.msoe.edv](lab6e2.png)](lab6e2.png)<figcaption>Error dialog when URL is http://www.msoe.edv</figcaption></figure> <figure>[![Error dialog when Timeout is set to 10 ms and the user attempts to reach http://www.msoe.edu](lab6e4.png)](lab6e4.png)<figcaption>Error dialog when Timeout is set to 10 ms and the user attempts to reach http://www.msoe.edu</figcaption></figure> <figure>[![Error dialog after user presses OK on the Connection Timeout dialog](lab6e5.png)](lab6e5.png)<figcaption>Resulting dialog after user presses <kbd>OK</kbd> on the Connection Timeout dialog</figcaption></figure> <figure>[![Error dialog when URL field is http://www.cnn.com/results.php](lab6e6.png)](lab6e6.png)<figcaption>Error dialog when URL is http://www.cnn.com/results.php</figcaption></figure> <figure>[![Error dialog when timeout is set to a negative value](lab6e7.png)](lab6e7.png)<figcaption>Error dialog when timeout is set to a negative value</figcaption></figure> <figure>[![Error dialog when an invalid URL is entered](lab6e8.png)](lab6e8.png)<figcaption>Error dialog when an invalid URL is entered</figcaption></figure> ## Coding Standard Additions for Exceptions The following additions to the coding standard must be observed when using expection handling. * General catch blocks (e.g., `(Exception e)` are avoided) * Catch blocks with auto-generated code (e.g., `e.printStackTrace()` or `// TODO`) are not left unmodified * Exceptions are only caught when a sensible response is placed in catch blocks ## 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 originally developed by [Dr. Walt Schilling](http://walterschilling.us) and updated by [Dr. Chris Taylor](/taylor/).

Monday, 13-Jan-2020 14:54:55 EST