Java Reference
In-Depth Information
E4.
Write (and test) a subclass of
JFrame
that has five components:
• in the east, a
JLabel
that contains “EAST”;
• in the west, a
JLabel
that contains “WEST”;
• in the north, a
JButton
that says “north”;
• in the south, a
JButton
that says “south”;
• in the center, a
JTextField
that initially contains “this is a text field”.
Sections 17.1.2 and17.1.3 give you the necessary information.
E5.
Write (and test) a subclass of
JFrame
that contains:
•a
JLabel
in the west that contains “color”;
•a
JTextField
in the east that initially contains: “red”;
Include a method
getTheField()
that returns the value in the
JTextField
, a
method
setTheField(s)
that changes the field to
String s
, and methods
make-
FieldEditable()
and
makeFieldUneditable()
with obvious meaning. Test
all this in the Interactions pane of DrJava by creating and showing an instance of
the subclass, calling the methods, and changing the value in the
JTextField
(by
typing into the field) several times. See Sec. 17.2.2.
E6.
Write (and test) a subclass of JFrame that contains:
• a JTextArea in the west that initially contains:
"The west\nwindow"
and
has no scroll bars.
• a JTextArea in the east that initially contains:
"The east\nwindow"
and
has scrollbars, if necessary.
Make both of the text areas 6 rows by 10 columns. Using DrJava's Interactions
pane, create and show an instance of this subclass and experiment with typing
text into the two text areas.
Add methods
dontWrap()
and
wrap()
to the subclass, which cause the text
not to wrap and to wrap. Create and show an instance of this subclass and exper-
iment with typing text and the wrap-nowrap methods.
See Sec. 17.2.2.
E7.
Write (and test) a subclass of JFrame that contains:
• a JTextArea in the west that initially contains:
"The west\nwindow"
and
has no scroll bars.
• a JTextArea in the east that initially contains:
"The east\nwindow"
and
has scrollbars, if necessary.
Make both of the text areas 6 rows by 10 columns. Include methods
getWest-
Area()
and
getEastArea()
that return the values in the text areas and methods
setEastArea(s)
and
setWestArea(s
) that change the fields to
String s
. Test
all this in the Interactions pane of DrJava by creating and showing an instance of
the subclass, calling the methods, and changing the values in the text areas (by
typing into them) several times. See Sec. 17.2.2.
E8.
Write (and test) a subclass of
JFrame
that contains:
•a
JCheckBox
in the east, with title “rain”;
•a
JRadioButton
in the west, with title “hot”.
Search WWH ::
Custom Search