trainwhistle.java
来自「21天学JAVA源代码」· Java 代码 · 共 25 行
JAVA
25 行
import java.applet.*;
import java.net.*;
public class TrainWhistle {
public static void main(String[] arguments) {
try {
URL bgSoundFile = new URL("file:train.wav");
AudioClip bgSound = Applet.newAudioClip(bgSoundFile);
URL beepFile = new URL("file:whistle.wav");
AudioClip beep = Applet.newAudioClip(beepFile);
if (bgSound != null)
bgSound.loop();
for (int i = 0; i < 10; i++) {
try {
Thread.sleep(9000);
if (beep != null)
beep.play();
} catch (InterruptedException e) { }
}
} catch (MalformedURLException mue) {
System.out.println("Bad URL: " + mue.getMessage());
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?