Java Reference
In-Depth Information
Display 17.7
The
BorderLayout
Manager
(part 1 of 2)
1
import
javax.swing.JFrame;
2
import
javax.swing.JLabel;
3
import
java.awt.BorderLayout;
4
public class
BorderLayoutJFrame
extends
JFrame
5{
6
public static final int
WIDTH = 500;
7
public static final int
HEIGHT = 400;
8
public
BorderLayoutJFrame()
9
{
10
super(
"BorderLayout Demonstration");
11
setSize(WIDTH, HEIGHT);
12
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
13
setLayout(
new
BorderLayout());
14
JLabel label1 =
new
JLabel("First label");
15
add(label1, BorderLayout.NORTH);
16
JLabel label2 =
new
JLabel("Second label");
17
add(label2, BorderLayout.SOUTH);
18
JLabel label3 =
new
JLabel("Third label");
19
add(label3, BorderLayout.CENTER);
20
}
21
}
This is the file
BorderLayoutJFrame.java
.
This is the file
BorderLayoutDemo.java
.
1
public class
BorderLayoutDemo
2{
3
public static void
main(String[] args)
4 {
5 BorderLayoutJFrame gui =
new
BorderLayoutJFrame();
6 gui.setVisible(
true
);
7 }
8}
(continued)