Java Reference
In-Depth Information
1. Write a class named CDFrame that extends javax.swing.JFrame.
Add a JTextArea in the center, two JTextField components in the
north (one for entering an artist and one for entering a title), and
add four buttons to the south: First, Previous, Next, and Last.
2. Write a class named CDListener that implements ActionListener.
Add two JTextField and one JTextArea fields and initialize them in a
constructor. They will be references to the GUI components of the
CDFrame.
3. Within the actionPerformed() method of CDListener, determine the
source of the action event. If it is a button, determine which of the
four navigation buttons was clicked and then perform the appropri-
ate action, displaying the CD in the text area. For example, if the
First button was clicked, so the first CD in the database. If the Next
button is clicked, show the next CD in the database and so on. Use
your CDDatabase class from Lab 18.1.
4. If the source of the ActionEvent is a JTextField, the user has typed
something in one of the text fields and has pressed Enter. This
means that the user wants to search the database for a given artist, a
given title, or both. Perform the desired search using the appropriate
methods of your CDDatabase class, then display the results in the
text area.
5. Save and compile your CDListener class.
6. In the constructor or your CDFrame class, instantiate a new CDLis-
tener and register it as an action listener to the four buttons and the
two text fields.
7. Add main() to your CDFrame class. Within main() instantiate a
CDFrame object, resize it, and make it visible.
8. Save, compile, and run your CDFrame class.
You should see your CDFrame GUI appear, and clicking the naviga-
tional buttons should display the corresponding CD in the text area.
Entering an artist's name and pressing Enter should display in the text
area all of the CDs in the database from that artist. Entering a title should
display all CDs in the database that contain the given text in part of the
title's name. For example, entering The in the title text field should dis-
play all CDs in the database with The in their title.
Search WWH ::




Custom Search