Java Reference
In-Depth Information
E9. Write (and test) a subclass of JFrame that contains:
• a radio button in the east, with title “rain”.
• a radio button in the center, with title “cloudy”.
• a radio button in the west, with title “sunny”.
Group them together in a ButtonGroup , and make “sunny” be checked when the
window is first shown. See Sec. 17.2.3.
E10. Write (and test) a subclass of JFrame that contains a JComboBox in the cen-
ter. It should have these entries: “rain”, “snow”, “cloudy”, “sunny”, with “sunny”
initially checked. Write a procedure addItem(s) that adds an item with title s to
the JCombobox . Experiment in DrJava's Interactions pane. See Sec. 17.2.3.
E11. Write (and test) a subclass of JFrame that contains a JList with a scroll bar
(if necessary) in the center. It should have these entries: “rain”, “snow”,
“cloudy”, “sunny”, “fog”, “hurricane”, with “sunny” initially checked. Experi-
ment with this in DrJava's Interactions pane. See Sec. 17.2.3.
E12. Write (and test) a subclass of JFrame that contains a JColorChooser in the
center. Experiment with it in DrJava's Interactions pane. See Sec. 17.2.3.
E13. Write (and test) a subclass of JFrame that contains:
•a JTextField in the north, with initial value "red" ;
• a red JPanel in the center, with preferred size 100 by 100 pixels.
The class should have a String field that initially contains "red" . It should have
a method newColor(s) , which changes the text field to s and then changes the
color of the JPanel accordingly —but only if s is one of "red" , "green" ,
"pink" , "white" , "black" , and "magenta" . See Sec. 17.2.4.
E14. Write (and test) a subclass of JFrame that contains:
•A JPanel in the north, which itself contains four buttons titled “one”,
“two”, “three”, “four”.
•A Box in the south, which itself contains four buttons titled “one”, “two”,
“three”, “four”.
Create and show an instance of this class. Then, experiment with it, by dragging
it to make it narrower and wider. What happens to the buttons in the JPanel ? In
the Box ? See Sec. 17.3.
E15. Write (and test) a subclass of JFrame that contains a Box in its center. This
Box should itself contain two rows and three columns. Each entry should be a
JLabel, with these titles:
"(a1, b2)"
"(a1, b3)"
"(a1, b4)"
"(a2, b2)"
"(a2, b3)"
"(a2, b4)
See Sec. 173.2.
E16. Write (and test) a JFrame that contains a Box in its center. This Box should
itself contain three rows:
• the first row contains two JLabel s with titles "left" and "right" .
 
Search WWH ::




Custom Search