Java Reference
In-Depth Information
5 Usability in the DVD Program
Add the following functionality to the DVD program created in this chapter.
Make sure that each function works before proceeding to the next. Include as
many functions as directed by your instructor.
a. When a user attempts to insert a new DVD, make the Cancel button that
displays in the JOptionPane input box work properly. Hint: Chapter 4
describes the use of the null constant.
b. Test input data for a valid Year before adding it to the String array.
c. Give users a choice of fonts by inserting two more menu options on the
Edit menu: one that says SansSerif and one that says Arial. Add function-
ality to the two items by using the setFontFamily() method.
d. Add a fourth array to the program with data about the director of the
movie. You may need to increase the size of the content pane. Remember to
add a new question to the Insert portion of the actionPerformed() method.
e. Reminder: The array must be sorted with each new entry.
6 Using Fonts
Write a Swing program to display the name of your school in a variety of fonts
and sizes. The interface should include a JTextPane, a Font combo box, and a
Font Size combo box. Use the insertString() method to display the name in the
JTextPane. Use at least two different fonts and three different sizes in the respec-
tive combo boxes. When the program runs, choosing different items from the
combo boxes should change the display.
7 Converting Code from AWT to Swing
Choose any Frame-based application that you have programmed before or one
suggested by your instructor and convert all the components to Swing compo-
nents. Remember to change the constructors, methods, and attributes. Create a
content pane to hold your Swing atomic components and extend JFrame.
8 Using Tutorials
Go to the following Web site: http://java.sun.com/docs/books/tutorial/uiswing/
components/components.html and work through the tutorial on Swing compo-
nents. Download at least one example of code explained in the tutorial. Compile
and run the code. Add comments to the code, and print a copy as directed by
your instructor.
J ava 2
J ava 2
v 5 . 0
v 5 . 0
9 Using Ocean Look and Feel
Open the DVD program you created in Chapter 7. Compile the program and
run it. Look at the various components in the interface, such as the title bar,
menus, drop-down boxes, and dialog boxes. Close the program and look at the
code in TextPad. Line 325 sets the look and feel to the user's operating system.
Comment out line 325 to cause the program to use the Ocean look and feel,
which is the default for J2SE version 5.0. Recompile and run the program again.
Make a table of all the components in the interface and describe the changes.
Turn the table in to your instructor.
Search WWH ::




Custom Search