本文整理汇总了Java中java.applet.AudioClip类的典型用法代码示例。如果您正苦于以下问题:Java AudioClip类的具体用法?Java AudioClip怎么用?Java AudioClip使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AudioClip类属于java.applet包,在下文中一共展示了AudioClip类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: playApplet
import java.applet.AudioClip; //导入依赖的package包/类
private static void playApplet(String filename) {
URL url = null;
try {
File file = new File(filename);
if (file.canRead())
url = file.toURI().toURL();
} catch (MalformedURLException e) {
throw new IllegalArgumentException("could not play '" + filename + "'", e);
}
// URL url = StdAudio.class.getResource(filename);
if (url == null) {
throw new IllegalArgumentException("could not play '" + filename + "'");
}
AudioClip clip = Applet.newAudioClip(url);
clip.play();
}
示例2: myKeyEvent
import java.applet.AudioClip; //导入依赖的package包/类
public Command myKeyEvent(KeyStroke stroke) {
myGetKeyCommands();
Command c = null;
if (command.matches(stroke)) {
final String clipName = format.getText(Decorator.getOutermost(this));
c = new PlayAudioClipCommand(clipName);
try {
final AudioClip clip = GameModule.getGameModule()
.getDataArchive()
.getCachedAudioClip(clipName);
if (clip != null) {
clip.play();
}
}
catch (IOException e) {
reportDataError(this, Resources.getString("Error.not_found", "Audio Clip"), "Clip="+clipName, e);
}
}
return c;
}
示例3: TravoltageAudio
import java.applet.AudioClip; //导入依赖的package包/类
public TravoltageAudio( TravoltageModel travoltageModel ) {
travoltageModel.addListener( new TravoltageModel.Listener() {
public void sparkStarted() {
}
public void sparkFinished() {
sparkFinished = true;
}
public void electronExitedFinger() {
if( sparkFinished ) {
play();
sparkFinished = false;
}
}
} );
AudioClip ouch = Applet.newAudioClip( findResource( "travoltage/audio/OuchSmallest.wav" ) );
AudioClip zzt = Applet.newAudioClip( findResource( "travoltage/audio/ShockSmallest.wav" ) );
this.clips = new AudioClip[]{ouch, zzt};
}
示例4: playApplet
import java.applet.AudioClip; //导入依赖的package包/类
private static void playApplet(String filename) {
URL url = null;
try {
File file = new File(filename);
if(file.canRead()) url = file.toURI().toURL();
}
catch (MalformedURLException e) {
throw new IllegalArgumentException("could not play '" + filename + "'", e);
}
// URL url = StdAudio.class.getResource(filename);
if (url == null) {
throw new IllegalArgumentException("could not play '" + filename + "'");
}
AudioClip clip = Applet.newAudioClip(url);
clip.play();
}
示例5: getJButton
import java.applet.AudioClip; //导入依赖的package包/类
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText("Add");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
File sound = new File("bddbddb.wav");
try {
AudioClip audioClip = Applet.newAudioClip(sound.toURL());
audioClip.play();
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
}
return jButton;
}
示例6: getFunDialog
import java.applet.AudioClip; //导入依赖的package包/类
public static Dialog getFunDialog() {
FileObject img = FileUtil.getConfigFile("BartGIfImage/BartSaturdayNightFever.gif");
FileObject audio = FileUtil.getConfigFile("BartAudio/STheme.wav");
final AudioClip clip = Applet.newAudioClip(audio.toURL());
Icon icon = new ImageIcon(img.toURL());
JLabel label = new JLabel(icon);
final Dialog dialog = new BartThemeDialog(WindowManager.getDefault().getMainWindow(), label);
label.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if(e.getClickCount() == 1) {
clip.stop();
dialog.dispose();
}
}
});
clip.loop();
return dialog;
}
示例7: playSound
import java.applet.AudioClip; //导入依赖的package包/类
/**
* Work method to play the sound.
*/
protected Object playSound(String soundToPlay) {
// Load it from the cache.
AudioClip clip = (AudioClip)soundCache.get(soundToPlay);
// Construct a new AudioClip and cache it.
if (clip == null) {
try{
clip = Applet.newAudioClip(ClassLoader.getSystemResource(soundToPlay));
soundCache.put(soundToPlay, clip);
} catch (NullPointerException npe){
} catch (NoSuchMethodError nsme){
}
}
// If the clip was somehow properly constructed or retrieved from the cache, play it.
if (clip != null) {
clip.play();
}
return "done";
}
示例8: playSound
import java.applet.AudioClip; //导入依赖的package包/类
/**
* Plays the Sound, constructing the clip from the Applet passed to the constructor.
* @overrides ApplicationSoundThreadManager.playSound
*/
protected Object playSound(String soundToPlay) {
// Load it from the cache.
AudioClip clip = (AudioClip)soundCache.get(soundToPlay);
// Construct a new AudioClip and cache it.
if (clip == null) {
try{
clip = soundSource.getAudioClip(new URL(soundSource.getParameter("SoundDirURL") + "/" + soundToPlay));
soundCache.put(soundToPlay, clip);
} catch (NullPointerException npe){
} catch (NoSuchMethodError nsme){
} catch (MalformedURLException mue){
System.out.println(mue.toString());
}
}
// If the clip was somehow properly constructed or retrieved from the cache, play it.
if (clip != null) {
clip.play();
}
return "done";
}
示例9: BarriersSelector
import java.applet.AudioClip; //导入依赖的package包/类
/**
* construct method . <br />
*
* @param default
* @param max
* @param offset
* @param w
* @param h
* @param icons
*/
public BarriersSelector( Battlefield bf, int defualt,
int max, int offset, int w, int h, ImageIcon[] icons, AudioClip buttonClip )
{
this.BF = bf;
this.barriers = defualt;
this.max = max;
this.offset = offset;
this.w = w;
this.h = h;
this.tImages = icons[0].getImage();
this.pImages = icons[1].getImage();
this.grass = icons[2];
this.buttonClip = buttonClip;
i_width = icons[0].getIconWidth();
i_height = icons[0].getIconHeight();
str_width = max * this.offset;
}
示例10: playClip
import java.applet.AudioClip; //导入依赖的package包/类
/**
* Plays an AudioClip.
*
* @param clip the audioclip to play.
*/
public void playClip(final AudioClip clip) {
final Runnable playThread = new Runnable() {
public void run() {
try {
clip.play();
}
catch (Exception ex) {
System.err.println("Unable to load sound file");
}
}
};
TaskEngine.getInstance().submit(playThread);
}
示例11: getAudio
import java.applet.AudioClip; //导入依赖的package包/类
public static AudioClip getAudio(int index) {
if (audios[index] == null) {
URL url = null;
ClassLoader classLoader = FileHelper.class.getClassLoader();
url = classLoader.getResource("music/" + index + ".wav");
audios[index] = Applet.newAudioClip(url);
}
return audios[index];
}
示例12: createAudioClipFactory
import java.applet.AudioClip; //导入依赖的package包/类
protected AudioClipFactory createAudioClipFactory() {
return new AudioClipFactory() {
public AudioClip getAudioClip(URL url) {
return Applet.newAudioClip(url);
}
};
}
示例13: playSound
import java.applet.AudioClip; //导入依赖的package包/类
/**
* Plays a sound based on
* the type parameter.
* @param type the sound type defined in
* Notification class.
*/
public void playSound(SoundType type) {
final AudioClip aClip = config.getSound(type);
if (aClip != null) {
aClip.play();
}
}
示例14: getSound
import java.applet.AudioClip; //导入依赖的package包/类
public AudioClip getSound(SoundType sound) {
if (sounds == null) {
SoundType[] soundsT = SoundType.values();
sounds = new HashMap<SoundType, AudioClip>();
String urlSound;
URL url;
for (SoundType st : soundsT) {
urlSound = sounds_path + st.name() + ".wav";
url = getClass().getResource(urlSound);
if (url == null) {
switch (st) {
case ERROR:
urlSound = sounds_path + SoundType.WARNING.name() + ".wav";
url = getClass().getResource(urlSound);
break;
case WARNING:
urlSound = sounds_path + SoundType.ERROR.name() + ".wav";
url = getClass().getResource(urlSound);
break;
default: // do nothing
}
if (url == null) {
urlSound = sounds_path + SoundType.MESSAGE.name() + ".wav";
url = getClass().getResource(urlSound);
}
}
if (url != null) {
sounds.put(st, Applet.newAudioClip(url));
}
}
}
return sounds.get(sound);
}
示例15: getAudioClip
import java.applet.AudioClip; //导入依赖的package包/类
public AudioClip getAudioClip(URL url) {
// We don't currently support audio clips in the Beans.instantiate
// applet context, unless by some luck there exists a URL content
// class that can generate an AudioClip from the audio URL.
try {
return (AudioClip) url.getContent();
} catch (Exception ex) {
return null;
}
}