当前位置: 技术问答>java相关
************在JAVA中发个声音好难啊,各位帮帮忙
来源: 互联网 发布时间:2015-02-15
本文导语: 代码如下,有什么错误 import java.awt.*; import java.applet.*; import java.awt.event.*; import java.net.*; public class playsound extends java.applet.Applet { public void init() { Button btn=new Button("play sound"); btn.addActionListener(new ActionListe...
代码如下,有什么错误
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.net.*;
public class playsound extends java.applet.Applet
{
public void init()
{
Button btn=new Button("play sound");
btn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try{
AudioClip ac=getAudioClip(getCodeBase(),"mes.au");
ac.play();}
catch(Exception ee)
{
System.out.println("error to play");
System.out.println(ee.getMessage());
}
}
});
add(btn);
}
}
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.net.*;
public class playsound extends java.applet.Applet
{
public void init()
{
Button btn=new Button("play sound");
btn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try{
AudioClip ac=getAudioClip(getCodeBase(),"mes.au");
ac.play();}
catch(Exception ee)
{
System.out.println("error to play");
System.out.println(ee.getMessage());
}
}
});
add(btn);
}
}
|
String[] mid = {
"http://localhost/G01.mid",
"http://localhost/G04.mid",
"http://localhost/G12.mid",
"http://localhost/G13.mid",
};
AudioClip audioClip = Applet.newAudioClip(new URL(/tech-qa-java/mid[3]/index.html));
audioClip.play();
"http://localhost/G01.mid",
"http://localhost/G04.mid",
"http://localhost/G12.mid",
"http://localhost/G13.mid",
};
AudioClip audioClip = Applet.newAudioClip(new URL(/tech-qa-java/mid[3]/index.html));
audioClip.play();
|
ile file = new File("bark.wav");
AudioClip clip = Applet.newAudioClip(file.toURL());
clip.play();
AudioClip clip = Applet.newAudioClip(file.toURL());
clip.play();