Java Reference
In-Depth Information
LISTING 11.1
The Full Text of Alphabet.java
1: import java.awt.*;
2: import java.awt.event.*;
3: import javax.swing.*;
4:
5: public class Alphabet extends JFrame {
6: JButton a = new JButton(“Alibi”);
7: JButton b = new JButton(“Burglar”);
8: JButton c = new JButton(“Corpse”);
9: JButton d = new JButton(“Deadbeat”);
10: JButton e = new JButton(“Evidence”);
11: JButton f = new JButton(“Fugitive”);
12:
13: public Alphabet() {
14: super(“Alphabet”);
15: setSize(360, 120);
16: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
17: FlowLayout lm = new FlowLayout(FlowLayout.LEFT);
18: setLayout(lm);
19: add(a);
20: add(b);
21: add(c);
22: add(d);
23: add(e);
24: add(f);
25: setVisible(true);
26: }
27:
28: public static void main(String[] arguments) {
29: Alphabet frame = new Alphabet();
30: }
31: }
Figure 11.1 shows the application running.
FIGURE 11.1
Six buttons
arranged in flow
layout.
In the Alphabet application, the flow layout manager uses the default gap of five pixels
between each component on a row and a gap of five pixels between each row. You can
change the horizontal and vertical gap between components with some extra arguments
to the FlowLayout() constructor.
 
Search WWH ::




Custom Search