Note: This lab is graded and will be worth 2 points toward your overall grade. You will have two lab sessions to complete it. Use the first session to familiarize yourself with graphical components and use the second to complete the actual exercise. You must complete your demonstration by the end of your second lab session in order to receive the 2 points.
We have just started discussing Java graphical applications and event-driven programming. In these applications the user interacts with the program via the use of a graphical interface -- for example a window with buttons and textfields and dialog boxes. Most consumer-oriented computer applications have graphical interfaces, so it is a good idea to get some practice in designing and implementing these applications.
In Lab 7 you completed the implementation of a simple Movie DB program, which allowed the user to list movies, search for a movie and add a new movie to the DB. The movies were loaded from a file and saved back to the file when the program terminated. You will now convert this program into one with a graphical interface. However the Movie class and MovieDB class will be IDENTICAL to those from Lab 7 (see files Movie.java and MovieDB.java). We are not changing the functionality of the DB, just the interface with the user.
To make the lab more feasible and more consistent, I have already written all but the event handlers for the main functionality of the program. Download this code and read it thoroughly (Lab8.java). For this lab you must implement the ControlListener class (which is the ActionListener for the JButtons) so that the program functions in a good, reasonable way.
Program
The Lab8.java program that you download should compile and run as given to you (as long as you also downloaded the Movie.java and MovieDB.java files). However, as given the buttons do nothing when clicked, because the actionPerformed() method of the ControlListener class contains no actual code. Run the program and look at the interface, then implement the ControlListener class as specified below: The functional aspects of the program should be as follows:
For options 1-3 above you must update the JTextArea in your program. This should be done in a nice way, so that only the data that is needed is shown and so that the JFrame is sized just enough to hold the data in the JTextArea (hint: pack()). See the demonstration by the TA for how your program should work.
Grading
Demonstrate that your program works correctly to your TA by running it for him / her.
Answer the question asked by your TA.
Your demonstration is due by your lab session the week of November 7-10 (see Lab page for your specific dates)
This lab is worth 2 grade points, distributed as shown below.
Since this lab is worth 2 points for your final grade, the points received will be divided by 10.0 to determine your final score.
Notes and Hints
Read the Lab8.java code given to you VERY
carefully before starting your own code. Also read over the various
handouts that were given on graphics and graphical components. You should
also look up some of the needed classes in the Java API (ex: JTextArea,
JOptionPane) so you know what methods to call and what arguments they require.
Think logically about what is supposed to happen in each situation and write
the handler appropriately.