Java Reference
In-Depth Information
Display 19.3
The
Runnable
Interface
(part 1 of 2)
1
import
javax.swing.JFrame;
2
import
javax.swing.JPanel;
3
import
javax.swing.JButton;
4
import
java.awt.BorderLayout;
5
import
java.awt.FlowLayout;
6
import
java.awt.Graphics;
7
import
java.awt.event.ActionListener;
8
import
java.awt.event.ActionEvent;
9
public class
ThreadedFillDemo2
extends
JFrame
10
implements
ActionListener, Runnable
11 {
12
public static final int
WIDTH = 300;
13
public static final int
HEIGHT = 200;
14
public static final int
FILL_WIDTH = 300;
15
public static final int
FILL_HEIGHT = 100;
16
public static final int
CIRCLE_SIZE = 10;
17
public static final int
PAUSE = 100; //
milliseconds
18
private
JPanel box;
19
public static void
main(String[] args)
20 {
21 ThreadedFillDemo2 gui =
new
ThreadedFillDemo2();
22 gui.setVisible(
true
);
23 }
24
public
ThreadedFillDemo2()
25 {
26 setSize(WIDTH, HEIGHT);
27 setTitle("Threaded Fill Demo");
28 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
29 setLayout(
new
BorderLayout());
30 box =
new
JPanel();
31 add(box, "Center");
32 JPanel buttonPanel =
new
JPanel();
33 buttonPanel.setLayout(
new
FlowLayout());
34 JButton startButton =
new
JButton("Start");
35 startButton.addActionListener(
this
);
36 buttonPanel.add(startButton);
37 add(buttonPanel, "South");
38 }
(continued)