Java Reference
In-Depth Information
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));
Alternatively, you could use new GridLayout(1, 0) . It is also possible to do
something similar with a BorderLayout manager or a FlowLayout manager, but a
GridLayout manager will work nicer here.
18.
The argument should be new GridLayout(0, 1) . So, the entire method invocation is
setLayout( new GridLayout(0, 1));
Alternatively, you could use new GridLayout(3, 1) , if you know there will be at
most three components added, but if more than three components are added,
then a second column will be added. It is also possible to do something similar
with a BorderLayout manager, but a GridLayout manager will work nicer here.
19. java.awt
20. An object of the class JPanel is both a container class and a component class.
21. To make it look as though you have an empty grid element, add an empty panel
to the grid element.
22. import javax.swing.JPanel;
import java.awt.Color;
public class PinkJPanel extends JPanel
{
public PinkJPanel()
{
setBackground(Color.PINK);
}
}
extra code
on CD
The class PinkJPanel is on the CD that accompanies this text.
23.
It will not compile, but will give a compiler error message saying that action-
Performed is not defined (since it claims to implement the ActionListener
interface).
Search WWH ::




Custom Search