Objectives
Students are given the option of developing this assignment as a desktop app with Swing or as an Android app. You are only required to do one of the two.
Common To Both Swing and Android
- Properly handle exceptions generated by an external class
- Use exception logging to track the occurrence of exceptions
Swing App
- Construct software which uses a
GridBagLayout
- Implement software with anonymous inner classes
- Implement action listeners to detect events in text entry boxes
- Integrate JOptionPane classes into the handling of exceptions
Android App
- Install Android Studio development environment
- Run Android application on emulator
Assignment
The web is 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 package 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. In specific, this application will:
- Allow us to enter a URL
- Download the content of the URL
- Inform us of the filesize
- Inform us of the time it takes to download the material
- Indicate which port the download is using
- Indicate the name of the host
You will be able to enter a valid URL and change the timeout, or how long we wait for the connection to be made.
WebsiteTester Class
You are to make use of a provided class: WebsiteTester
(javadoc). This class is prebuilt in
provided in a lab6.jar file. This class connects
with the web server and analyzes the connection.
Desktop Application Details
You must write the WebsiteTesterUI
class. You must use a
GridBagLayout
layout manager.
Android App Details
First you will need to install the Android development environment on your computer.
Students doing the Android app should download the lab6.zip 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:
- Unzip the file and place the
Lab6
folder at the root of the D: drive (D:\Lab6
) - Start Android Studio
- Select
Open an existing Android Studio project
- Browse to
D:\Lab6
and clickOK
- Change
Gradle project
toD:\Lab6
- Ensure that
Use default gradle wrapper (recommended)
is selected - Click
OK
and wait until the project opens and the gradle tasks complete - Open the
WebsiteTesterActivity
class by expanding theapp -> java -> edu.msoe.se1021
folder structure in the project pane
Operation
Operation of the program begins with the user starting the program. The
program will start with http://msoe.us/taylor/se1021/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 dialog box. When the
user presses the enter key, an event will cause the URL to be sent
to the WebsiteTester
instance.
Students implementing the Android version of the assignment should refer
to the TODO comments in the WebsiteTesterActivity
class to determine exactly what needs to be done.
Students implementing the desktop version of the assignment should refer to the sequence diagram below to determine exactly what needs to be done.
Exception Handling
All exceptions generated shall be logged. The desktop application must use the Logger
class. In specific, all exceptions shall be written to the file exceptions.log
. The Android app must use the Log class.
Invalid URL in text field when user presses enter
In the event that the user enters an invalid URL in the text field and presses enter, a message dialog box shall be opened indicating that the text entered in the text field is invalid and the URL will be set to an empty string. Note: the Android app does not respond to enter being pressed in the URL text field, so this only applies to the desktop application.
Invalid Timeout
If the timeout is invalid when an attempt is made to set the timeout, a message dialog box shall be opened indicating that an invalid timeout has been entered by the user. When the dialog closes, the text in the text field shall revert 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 shall be issued and the url shall be set to a blank entry.
If there is a socket timeout exception, a confirmation dialog shall be opened indicating that the connection has timed out and asking if they would like to extend the timeout. If they would like to extend the timeout, then an input dialog shall be opened allowing the user to set the new timeout.
If the host cannot be found, a message shall be displayed indicating that the user has attempted to reach a host which does not exist.
If a general IO error occurs, a message shall be shown indicating that there was a problem reading from the given file.
The desktop application should use JOptionPane
dialogs. The Android application should use the ErrorDialog
and SocketDialog
classes provided in the Android project.
Sample Error Dialogs
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 Dr. Rebenitsch for instructions
Dr. Taylor's students: See below
See Prof. Ung for instructions
Acknowledgment
This laboratory assignment was developed by Dr. Walt Schilling. Prof. Baohuy Ung developed the Android implementation.