Biblioteca Java - Blame information for rev 29
Subversion Repositories:
Rev | Author | Line No. | Line |
---|---|---|---|
29 | mihai | 1 | package exemple.fire.timer2; |
2 | |||
3 | import java.awt.Toolkit; | ||
4 | import java.util.Timer; | ||
5 | import java.util.TimerTask; | ||
6 | |||
7 | |||
8 | |||
9 | public class AnnoyingBeep { | ||
10 | Toolkit toolkit; | ||
11 | Timer timer; | ||
12 | |||
13 | public AnnoyingBeep() { | ||
14 | toolkit = Toolkit.getDefaultToolkit(); | ||
15 | timer = new Timer(); | ||
16 | timer.schedule(new RemindTask(), | ||
17 | 0, //initial delay | ||
18 | 1*800); //subsequent rate | ||
19 | } | ||
20 | |||
21 | class RemindTask extends TimerTask { | ||
22 | int numWarningBeeps = 3; | ||
23 | public void run() { | ||
24 | if (numWarningBeeps > 0) { | ||
25 | toolkit.beep(); | ||
26 | System.out.format("Beep!%n"); | ||
27 | numWarningBeeps--; | ||
28 | } else { | ||
29 | toolkit.beep(); | ||
30 | System.out.format("Time's up!%n"); | ||
31 | //timer.cancel(); //Not necessary because | ||
32 | //we call System.exit | ||
33 | System.exit(0); //Stops the AWT thread | ||
34 | //(and everything else) | ||
35 | } | ||
36 | } | ||
37 | } | ||
38 | |||
39 | public static void main(String[] args) { | ||
40 | AnnoyingBeep ab = new AnnoyingBeep(); | ||
41 | } | ||
42 | |||
43 | |||
44 | } |