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. ## 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 `` 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`]( and [`TextInputDialog`]( dialogs when responding to errors (see [examples]( ### 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](lab6e4.png)](lab6e4.png)<figcaption>Error dialog when Timeout is set to 10 ms and the user attempts to reach</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](lab6e6.png)](lab6e6.png)<figcaption>Error dialog when URL is</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> ## 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 ## Just for Fun Once the basic requirements of the assignment have been met, you may be interested in an additional challenge. Here are a couple of ideas: * Make use of the `WebView` class to display the results of the web request as HTML. * Redo the lab assignment as an Android app. ### Android App Details First you will need to [install the Android development environment on your computer]( <figure>[![Android App](lab6d.png)](lab6d.png)<figcaption>Android App</figcaption></figure> Students doing the Android app should download the []( file which contains the complete Android Studio project. All of the required changes are in the `WebsiteTesterActivity` class and identified with **TODO** comments. To load the project: 1. Unzip the file and place the `Lab6` folder at the root of the D: drive (`D:\Lab6`) 1. Start Android Studio 1. Select **`Open an existing Android Studio project`** 1. Browse to `D:\Lab6` and click `OK` 1. Change `Gradle project` to **`D:\Lab6`** <figure>[![Gradle Dialog](lab6f.png)](lab6f.png)<figcaption>Gradle Dialog</figcaption></figure> 1. Ensure that `Use default gradle wrapper (recommended)` is selected 1. Click **`OK`** and wait until the project opens and the gradle tasks complete 1. Open the `WebsiteTesterActivity` class by expanding the `app -> java -> edu.msoe.se1021` folder structure in the project pane 1. Instead of `JOptionPane` the Android application should use the `ErrorDialog` and `SocketDialog` classes provided in the Android project. 1. The Android app does not respond to enter being pressed in the URL text field, so the invalid URL exception must be handled differently. <figure>[![Project Pane](lab6g.png)](lab6g.png)<figcaption>Project Pane</figcaption></figure> ## 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]( and updated by [Dr. Chris Taylor](/taylor/). Prof. Baohuy Ung developed the Android implementation.

Monday, 22-Jan-2018 14:44:31 CST