Biblioteca Java - Rev 29
Subversion Repositories:
package exemple.fire.timer2;
import java.awt.Toolkit;
import java.util.Timer;
import java.util.TimerTask;
public class AnnoyingBeep {
Toolkit toolkit;
Timer timer;
public AnnoyingBeep() {
toolkit = Toolkit.getDefaultToolkit();
timer = new Timer();
timer.schedule(new RemindTask(),
0, //initial delay
1*800); //subsequent rate
}
class RemindTask extends TimerTask {
int numWarningBeeps = 3;
public void run() {
if (numWarningBeeps > 0) {
toolkit.beep();
System.out.format("Beep!%n");
numWarningBeeps--;
} else {
toolkit.beep();
System.out.format("Time's up!%n");
//timer.cancel(); //Not necessary because
//we call System.exit
System.exit(0); //Stops the AWT thread
//(and everything else)
}
}
}
public static void main(String[] args) {
AnnoyingBeep ab = new AnnoyingBeep();
}
}
import java.awt.Toolkit;
import java.util.Timer;
import java.util.TimerTask;
public class AnnoyingBeep {
Toolkit toolkit;
Timer timer;
public AnnoyingBeep() {
toolkit = Toolkit.getDefaultToolkit();
timer = new Timer();
timer.schedule(new RemindTask(),
0, //initial delay
1*800); //subsequent rate
}
class RemindTask extends TimerTask {
int numWarningBeeps = 3;
public void run() {
if (numWarningBeeps > 0) {
toolkit.beep();
System.out.format("Beep!%n");
numWarningBeeps--;
} else {
toolkit.beep();
System.out.format("Time's up!%n");
//timer.cancel(); //Not necessary because
//we call System.exit
System.exit(0); //Stops the AWT thread
//(and everything else)
}
}
}
public static void main(String[] args) {
AnnoyingBeep ab = new AnnoyingBeep();
}
}