blob: 57eb464f4b1a79db5b69111a92ca781954f0470a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
package gjt.test;
import java.awt.*;
import gjt.Bargauge;
/**
* A lone Barguage which animates. This unit test is meant to
* illustrate that a Bargauge can cope with having its
* orientation chanaged from horizontal to vertical or
* vice-versa. This test is best run in appletviewer, so that
* the window may be resized such that the Bargauge changes its
* orientation.<p>
*
* <em>
* Warning: An AWT bug causes this test to be a gluttenous
* consumer of resources (especially under Win95). A mouse down
* will halt the animation thread along with its consumption of
* resources.<p>
* </em>
*
* @version 1.0, April 25, 1996
* @author David Geary
* @see gjt.test.UnitTest
* @see gjt.Bargauge
*/
public class SimpleBargaugeTest extends UnitTest {
public String title() {
return "Simple Bargauge Test";
}
public Panel centerPanel() {
return new SimpleBargaugeTestPanel();
}
}
class SimpleBargaugeTestPanel extends Panel implements Runnable {
private Bargauge gauge = new Bargauge(Color.blue);
private boolean running = true;
private Thread t;
public SimpleBargaugeTestPanel() {
setLayout(new BorderLayout());
add("Center", gauge);
t = new Thread(this);
t.start();
}
public void run() {
while(true) {
try { Thread.currentThread().sleep(500,0); }
catch(InterruptedException e) { }
gauge.setFillPercent(Math.random() * 100);
gauge.fill();
}
}
public boolean mouseDown(Event event, int x, int y) {
if(running) { t.suspend(); running = false; }
else { t.resume (); running = true; }
return true;
}
}
|