Java Reference
In-Depth Information
• the second row contains one
JTextField
with 5 rows and 30 columns. Put
whatever you want in it.
• the third row contains three
JButton
s labeled
"yes"
,
"no"
, and
"cancel
".
See Sec. 17.3.2.
E17.
Write (and test) a subclass of JFrame that contains the two buttons as shown
in Fig. 17.13. Exactly one should be enabled at any time, and clicking one of the
enabled one enables the other. See Sec. 17.4.1.
E18.
Write (and test) a subclass of
JFrame
that contains a rectangle of four but-
tons labeled
"top-left"
,
"top-right"
,
"bot-left"
, and
"bot-right"
. Only
one should be enabled at any time, and clicking the enabled one enables the next
one in clockwise order. See Sec. 17.41.
E19.
Add a
JLabel
to the subclass of exercise E18. The label should always have
the same title that the enabled button has.
E20.
Add a method
change(s)
to the subclass of exercise E19. Parameter
s
has
to be one of the strings
"top-left"
,
"top-right"
,
"bot-left"
, and
"bot-
right"
(if it is anything else, a call should terminate without doing anything).
Change the enabled button (and the label) to the one given by
s
.
E21.
Write (and test) a subclass of
JFrame
that contains a button title
"rotate"
in the north and a
Box
of three colored
JPanel
s in the center —make them a rea-
sonable size, through trial and error. One
JPanel
should be red, one white, and
one blue. Whenever button rotate is clicked, the colors should rotate one position
to the right —the blue becomes white, the white becomes red, and the red
becomes blue.
E22.
Class
Square
of Fig 17.16 is either green or red and may have a pink disk
on it. Change the background color to be either green or pink. Then, modify the
class so that it can have either a red or a black disk (or nothing) on it, as in the
game of checkers. This means having suitable methods to place a disk and to
remove any disk on the square.
E23.
Write (and test) a subclass of
JFrame
that has a row of four
Square
s on it,
as given in exercise E22. Initially, each Square should have nothing on it. Also,
the subclass should have two text fields and a button. The user should be able to
type a number (
1
,
2
,
3
, or
4
) into the first text field, either
""
or
"black"
or
"red"
into the second text field, and click the button. This should result in the
designated square having either nothing, a black disk, or a red disk on it. If the
user typed something else in either of these fields, no change should be made.
Search WWH ::
Custom Search