看板 java 關於我們 聯絡資訊
各位大哥好: 因為想在applet上放音樂,所以自己先做了一個測試, 就是按按鈕就會播放在同一個資料夾下的音效檔,但是不知道為什麼好像沒辦法執行.. 我是參考這個網站: http://big5.china-code.net/read/7/6/165648.html 我的程式碼: public class applet7 extends JApplet implements ActionListener{ JButton But; applet7 ap; public void init(){ But=new JButton("play"); ap=new applet7(); Container pane=this.getContentPane(); pane.setLayout(new GridLayout(1,1)); pane.add(But); this.But.addActionListener(this); } public void actionPerformed(ActionEvent e){ if(e.getSource()==But){ AudioClip temp=ap.getAudioClip(getDocumentBase(),"SAX.au"); temp.play(); But.setEnabled(false); } } } 試過.wav和.mp3檔也都沒效..編譯是會過但是按鈕按下去就像軟墊一樣,滑鼠移開 才恢復正常,也沒有執行setEnabled的樣子.. 另外想問一下AudioClip是Interface吧?還是有一個class也叫AudioClip? 麻煩各位高手解答了 謝謝!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.164.103.80
akaing:試試看newAudioClip() 關鍵字查查看 07/31 11:35
akaing:class or Interface go over this http://0rz.tw/lryiD 07/31 11:37
akaing:其他調用先看這裡提供的API http://0rz.tw/GiOHY 07/31 11:39
akaing:getDocumentBase() Gets the URL of the document 07/31 12:03
akaing:in which "this applet is embedded". 開個html嵌入也可 07/31 12:05
PsMonkey:亂入題外話:HTML5 快統一世界吧 [握拳] 07/31 12:17
tempTTP1:感謝~ 07/31 21:33
tempTTP1:但是URL建立物件時compiler說要用throw或是catch才行 07/31 22:04
tempTTP1:可是我改了之後又說URL class不是throwable..怎麼會這樣? 07/31 22:07
akaing:throws Exception? 試試看用classLoader.getReosurce() 08/10 06:48