注:A.java使用了未经检查或不安全的操作。 注:有关详细信息,请使用-Xlint:unchecked重新编译。
importjava.awt.*;importjava.net.*;importjava.awt.event.*;importjava.io.*;importjava.a...
import java.awt.*;
import java.net.*;
import java.awt.event.*;
import java.io.*;
import java.applet.*;
import javax.swing.*;
public class AudioClipDialog extends JDialog implements Runnable,
ItemListener,ActionListener{
Thread thread;
JComboBox choiceMusic;
AudioClip clip;
JButton buttonPlay,
buttonLoop,
buttonStop;
String str;
AudioClipDialog(){
thread = new Thread(this);
choiceMusic = new JComboBox();
choiceMusic.addItem("选择音频文件");
choiceMusic.addItem("musicOne.wav");
choiceMusic.addItem("musicTwo.wav");
choiceMusic.addItem("musicThree.wav");
choiceMusic.addItemListener(this);
buttonPlay = new JButton("播放");
buttonLoop = new JButton("循环");
buttonStop = new JButton("停止");
buttonPlay.addActionListener(this);
buttonStop.addActionListener(this);
buttonLoop.addActionListener(this);
setLayout(new FlowLayout());
add(choiceMusic);
add(buttonPlay);
add(buttonLoop);
add(buttonStop);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(350,120);
}
public void itemStateChanged(ItemEvent e){
str = choiceMusic.getSelectedItem().toString();
if(!(thread.isAlive())){
thread = new Thread(this);
}
try{
thread.start();
}
catch(Exception ee){ };
}
public void run(){
try{ File file = new File(str);
URI uri = file.toURI();
URL url = uri.toURL();
clip = Applet.newAudioClip(url);
}
catch(Exception e){ }
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == buttonPlay)
clip.play();
else if(e.getSource() == buttonLoop)
clip.loop();
else if(e.getSource() == buttonStop)
clip.stop();
}
} 展开
import java.net.*;
import java.awt.event.*;
import java.io.*;
import java.applet.*;
import javax.swing.*;
public class AudioClipDialog extends JDialog implements Runnable,
ItemListener,ActionListener{
Thread thread;
JComboBox choiceMusic;
AudioClip clip;
JButton buttonPlay,
buttonLoop,
buttonStop;
String str;
AudioClipDialog(){
thread = new Thread(this);
choiceMusic = new JComboBox();
choiceMusic.addItem("选择音频文件");
choiceMusic.addItem("musicOne.wav");
choiceMusic.addItem("musicTwo.wav");
choiceMusic.addItem("musicThree.wav");
choiceMusic.addItemListener(this);
buttonPlay = new JButton("播放");
buttonLoop = new JButton("循环");
buttonStop = new JButton("停止");
buttonPlay.addActionListener(this);
buttonStop.addActionListener(this);
buttonLoop.addActionListener(this);
setLayout(new FlowLayout());
add(choiceMusic);
add(buttonPlay);
add(buttonLoop);
add(buttonStop);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(350,120);
}
public void itemStateChanged(ItemEvent e){
str = choiceMusic.getSelectedItem().toString();
if(!(thread.isAlive())){
thread = new Thread(this);
}
try{
thread.start();
}
catch(Exception ee){ };
}
public void run(){
try{ File file = new File(str);
URI uri = file.toURI();
URL url = uri.toURL();
clip = Applet.newAudioClip(url);
}
catch(Exception e){ }
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == buttonPlay)
clip.play();
else if(e.getSource() == buttonLoop)
clip.loop();
else if(e.getSource() == buttonStop)
clip.stop();
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询