Description
Lab 8
1. Introduction
This lab aims to introduce the student to the basics of creating a graphical user interface (GUI) using Java. If you have not revied the lectures on GUI, you will not be able to do this lab.
2. Grading Criteria (Please review before starting)
Criterion Mark(s)
Main method implemented to pass SmogApp object to SmogGUI constructor at start up. 1
Functionality of the Clear and Exit buttons (0.5 each) 1
Functionality of the Save button 1
Functionality of the Clear All button 1
Colors and error handling (fields are checked for numeric input) 1
A PENALTY OF 0.5 MARKS WILL BE APPLIED FOR EACH OF THE FOLLOWING:
• Writing public methods other than those specified.
3. Smog Level Collection
The Municipal Corporation needs a program to log smog levels surrounding the city dump. On any given day, inspectors take measurements of smog levels at various distances from the dump and record these measurements. The application needs a graphical user interface (GUI). You will create the GUI in this lab.
Specific objectives of the lab are:
• Integrating a GUI with an application
• Adding components to a GUI
• Writing listeners for GUI components
•
The GUI that you will create is illustrated on the next page.
Java code for two classes is provided. The classes are:
SmogApp maintains a log of smog level readings.
SmogGUI starter code for the GUI
Please download these two classes and load them into a project for this lab. Spend a few moments to get acquainted with the code. Note especially how the Reading class is used and the methods that are defined by the SmogApp class.
Figure 1: The Smog Meter GUI
Instructions
1. Modify the code of the SmogGUI class so that this class holds an instance of the SmogApp class as an attribute.
2. Modify the constructor of the SmogGUI class to accept the SmogApp object as a parameter.
3. Write a main method (either as part of the SmogGUI code, or in a tester class) that creates an instance of the SmogGUI class. Running this method should cause the GUI to be displayed.
4. Add a button labelled “Exit” to the GUI. This button shall be displayed in the last row, to the right of the button labelled “Clear All”.
5. Change the colours of the form to colours of your pleasing.
6. Implement listeners for the buttons as follow:
a) When the Clear button is clicked the fields labelled Distance, and Smog Level should be cleared.
b) When the Clear All button is clicked, the GUI shall invoke the appropriate method of the SmogApp object to clear the list of readings and shall also update the display.
c) When the Exit button is clicked the GUI shall close.
d) When the Save button is clicked the GUI shall check the fields labelled Distance and Smog Level for the values entered there. If either field is blank, or contains an illegal value (i.e. not numeric) then nothing should be done. If the data in the fields is acceptable than the GUI shall invoke the addReading method of the SmogApp object to store the new readings and shall also cause the display of readings to be updated.
4. Get Graded
You must get your work graded by a Lab Tech before the end of the lab – even though we will demonstrate that your program works, you must have entries in the tables before you get graded.
5. Submit
Download your files from repl and submit a zip file using the submission link on OurVLE with your SmogAPP.java and SmogGUI.java files. Ensure that you put your id number as a comment on the first line of each file.
Reviews
There are no reviews yet.