Java Reference
In-Depth Information
10. Delete
setTitle("First Window Class");
and replace
super
();
with
super
("First Window Class");
11. Change
setDefaultCloseOperation(
JFrame.DO_NOTHING_ON_CLOSE);
to
setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE);
12. Change the following line in the no-argument constructor in Display 17.6 from
this
(Color.PINK);
to
this
(Color.MAGENTA);
13.
add(
new
JLabel("Close-window button works."));
14. Yes, it is legal. It is OK to reuse a variable name such as
aLabel
.
15. You need to change the
add
statements, as in the following rewritten section
of code:
JLabel label1 =
new
JLabel("First label");
add(label1, BorderLayout.NORTH);
JLabel label2 =
new
JLabel("Second label");
add(label2, BorderLayout.CENTER);
JLabel label3 =
new
JLabel("Third label");
add(label3, BorderLayout.SOUTH);
16. You need to change the
add
statements, as in the following rewritten section
of code:
JLabel label1 =
new
JLabel("First label");
add(label1, BorderLayout.NORTH);
JLabel label2 =
new
JLabel("Second label");
add(label2, BorderLayout.EAST);
JLabel label3 =
new
JLabel("Third label");
add(label3, BorderLayout.SOUTH);
17. The argument should be
new GridLayout(1, 3)
. So, the entire method
invocation is
setLayout(
new
GridLayout(1, 3));