📄 example8_14.java.bak
字号:
import java.applet.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Example8_14 extends Applet
{
JButton play,loop,stop;
AudioClip audio = null;
public void init()
{
resize(200,30);
play = new JButton("play");
loop = new JButton("Loop");
stop = new JButton("Stop");
stop.setEnabled(false);
audio = getAudioClip(getCodeBase(),"笨小孩.mid");
add(play);
play.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent event) {
playActionPerformed(event);
}
}
);
add(loop);
loop.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent event) {
loopActionPerformed(event);
}
}
);
add(stop);
stop.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent event) {
stopActionPerformed(event);
}
}
);
}
private void playActionPerformed(ActionEvent event)
{
if(audio!=null)
{
audio.play();
play.setEnabled(false);
loop.setEnabled(false);
stop.setEnabled(true);
showStatus("playing sound only once!");
}
else
showStatus("Sound file no loaded");
}
private void loopActionPerformed(ActionEvent event)
{
if(audio!=null)
{
audio.loop();
play.setEnabled(false);
loop.setEnabled(false);
stop.setEnabled(true);
showStatus("Playing sound all the time!");
}
else
showStatus("Sound file not loaded");
}
private void stopActionPerformed(ActionEvent event)
{
audio.stop();
loop.setEnabled(true);
stop.setEnabled(false);
showStatus("Stop playing sound!");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -