java 小综合
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;
import java.io.InputStream;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
public class Audio extends JFrame implements ActionListener{
ImageIcon c1=new ImageIcon("D:\\2.jpg");
JLabel la;
JButton start;
AudioStream as;
public Audio()
{
super("sdfhg");
setLayout(null);
setBounds(222, 220, 580, 620);
try{
InputStream in = new FileInputStream ("D:\\渴望.au");
//打开一个声音文件流作为输入
as = new AudioStream (in);
}catch( Exception e){
e.printStackTrace();
}
la=new JLabel();
la.setIcon(c1);
//la.setBounds(0, 0, 450, 468);
start=new JButton("start");
start.addActionListener(this);
add(la);
add(start);
start.setBounds(500,0,50,30);
la.setBounds(0,0,450,468);
setVisible(true);
}
/**
* @param args
*/
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(as==null)
System.out.print("meizhao");
Object ss=e.getSource();
if(ss==start)
AudioPlayer.player.stop(as);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Audio au=new Audio();
}
}