/Users/lyon/j4p/src/gui/run/RunScroll.java
|
1 package gui.run;
2
3 import gui.ClosableJFrame;
4
5 import javax.swing.*;
6 import java.awt.BorderLayout;
7 import java.awt.Container;
8 import java.awt.GridLayout;
9 import java.awt.event.AdjustmentEvent;
10 import java.awt.event.AdjustmentListener;
11
12 public abstract class RunScroll
13 extends JScrollBar
14 implements
15 AdjustmentListener,
16 Runnable {
17 public RunScroll(int orientation,
18 int value,
19 int extent,
20 int min,
21 int max) {
22 super(orientation,
23 value,
24 extent,
25 min,
26 max);
27 addAdjustmentListener(this);
28 }
29
30 public RunScroll(int orientation) {
31 this(orientation, 0, 10, 0, 100);
32 }
33
34 public RunScroll() {
35 this(VERTICAL);
36 }
37
38 public void adjustmentValueChanged(AdjustmentEvent ae) {
39 SwingUtilities.invokeLater(this);
40 }
41
42 private static JPanel getScrollBars(int orientation, int n) {
43 JPanel jp = new JPanel();
44 if (orientation == RunScroll.VERTICAL)
45 jp.setLayout(new GridLayout(1, 0));
46 else
47 jp.setLayout(new GridLayout(0, 1));
48 for (int i = 0; i < n; i++)
49 jp.add(new RunScroll(orientation) {
50 public void run() {
51 System.out.println("value=" + getValue());
52 }
53 });
54 return jp;
55 }
56
57 public static void main(String args[]) {
58 ClosableJFrame cf = new ClosableJFrame();
59 cf.setSize(200, 200);
60 Container c = cf.getContentPane();
61 c.setLayout(new BorderLayout());
62 int n = 9;
63 c.add(getScrollBars(RunScroll.HORIZONTAL, n), BorderLayout.NORTH);
64 c.add(getScrollBars(RunScroll.HORIZONTAL, n), BorderLayout.SOUTH);
65 c.add(getScrollBars(RunScroll.VERTICAL, n), BorderLayout.EAST);
66 c.add(getScrollBars(RunScroll.VERTICAL, n), BorderLayout.WEST);
67 cf.setVisible(true);
68 }
69 }