一共八轮,每轮响八次。
每次从1开始 ,到8截止。每隔400ms发出蜂鸣声。
-
package week15;
import java.awt.Frame;
import java.awt.Toolkit;
class BeepThread extends Thread{
Thread t = Thread.currentThread();
boolean flag = true;
public void run() {
while(flag)
bee();
}
//蜂鸣声
public void bee(){
boolean isBee = true;
for(int k=1;k<9;k++){
if(isBee){
Frame f=new Frame();
Toolkit kit = f.getToolkit();
kit.beep();
System.out.print(k+"\t");
try {
Thread.sleep(400);//每隔400ms发出蜂鸣声
} catch (InterruptedException e) {
e.printStackTrace()