隨機數:
Random[type,range] : 產生type類型并且在RANGE范圍內均勻的分布隨機數。
Random[] : 0-1上的隨機數。
SeedRandom[n] : 以n為seed產生偽隨機數。
Randomldistribution : 可以產生各種分布。
獲取背景音樂源代碼:
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.applet.AudioClip;
public class LX_Thread extends Applet implements ItemListener,ActionListener
{
AudioClip sound;
Choice c=new Choice();
Button play=new Button("播放");
Button loop=new Button("連續");
Button stop=new Button("停止");
public void init(){
c.add("t.wav"); c.add("y.wav"); c.add("yd.wav");
add(c);
c.addItemListener(this);
add(play);add(loop);add(stop);
play.addActionListener(this);
loop.addActionListener(this);
stop.addActionListener(this);
sound=getAudioClip(getCodeBase(),"t.wav");
sound.play();
}
public void itemStateChanged(ItemEvent e){
sound.play();
//sound=getAudioClip(getCodeBase(),c.getSelectedItem());//"WAV/"+
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==play) sound.play();
else if(e.getSource()==loop) sound.loop();
else if (e.getSource()==stop) sound.stop();
}
}
新聞熱點
疑難解答