[問題] 請問applet怎麼播放音效?

看板java作者 (任劍翔)時間15年前 (2010/07/31 10:01), 編輯推噓4(406)
留言10則, 3人參與, 最新討論串1/1
各位大哥好: 因為想在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

07/31 11:35, , 1F
試試看newAudioClip() 關鍵字查查看
07/31 11:35, 1F

07/31 11:37, , 2F
class or Interface go over this http://0rz.tw/lryiD
07/31 11:37, 2F

07/31 11:39, , 3F
其他調用先看這裡提供的API http://0rz.tw/GiOHY
07/31 11:39, 3F

07/31 12:03, , 4F
getDocumentBase() Gets the URL of the document
07/31 12:03, 4F

07/31 12:05, , 5F
in which "this applet is embedded". 開個html嵌入也可
07/31 12:05, 5F

07/31 12:17, , 6F
亂入題外話:HTML5 快統一世界吧 [握拳]
07/31 12:17, 6F

07/31 21:33, , 7F
感謝~
07/31 21:33, 7F

07/31 22:04, , 8F
但是URL建立物件時compiler說要用throw或是catch才行
07/31 22:04, 8F

07/31 22:07, , 9F
可是我改了之後又說URL class不是throwable..怎麼會這樣?
07/31 22:07, 9F

08/10 06:48, , 10F
throws Exception? 試試看用classLoader.getReosurce()
08/10 06:48, 10F
文章代碼(AID): #1CKuG93B (java)