SE450: Adding Components [22/41] Previous pageContentsNext page

.

file:horstmann/ch04_frame/FrameTester.java [source] [doc-public] [doc-private]
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package horstmann.ch04_frame;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class FrameTester
{
  public static void main(String[] args)
  {
    JFrame frame = new JFrame();

    JButton helloButton = new JButton("Say Hello");
    JButton goodbyeButton = new JButton("Say Goodbye");

    final int FIELD_WIDTH = 20;
    JTextField textField = new JTextField(FIELD_WIDTH);
    textField.setText("Click a button!");

    frame.setLayout(new FlowLayout());

    frame.add(helloButton);
    frame.add(goodbyeButton);
    frame.add(textField);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
  }
}

Previous pageContentsNext page