我試圖將播放方法放在我的Audioapp
類中,位於我的ActionListener
中,我嘗試將其放入,但出現錯誤。試圖在我的ActionListener中放置播放音頻方法
我看過的javadoc上ActionListener
但無法找到它
這是我的聲音:
public class Audioapp extends JApplet // find out how to implement play method into action listener?
{
public class Sound // Holds one audio file
{
private AudioClip song; // Sound player
private URL songPath; // Sound path
Sound(String filename)
{
try
{
songPath = new URL(getCodeBase(),"G:\\Uni\\Programming\\Rolling assignements\\Week0\\Programming week21"); // This is the place were im getting error
song = Applet.newAudioClip(songPath); // Load the Sound
}
catch(Exception e){e.printStackTrace();}
}
public void playSound()
{
song.play(); // Play
}
}
}
這是我actionListener
:
class PlayStoHandler implements ActionListener {
public void actionPerformed(ActionEvent event) {
String computerRand = sps.computerChoice();
txtComputerRand.setText(computerRand);
String result = sps.play(Sps.ROCK);
txtResult.setText(result);
scis.setVisible(false);
open.setVisible(false);
stone.setVisible(true);
pap.setVisible(false);
win.setVisible(false);
none.setVisible(false);
lose.setVisible(false);
if (result == "User Wins"){
win.setVisible(true);
song.play(); // here i tried putting the song.play in this if section, the error I got was "song cannot be resolved"
}
else if (result == "Draw"){
none.setVisible(true);
}
else {
lose.setVisible(true);
}
}
我是初學者所以它很可能是一個非常愚蠢的基本錯誤
任何幫助將不勝感激
1)你能得到血腥的代碼格式嗎?!? 2)*「但是得到了錯誤。」*喜歡什麼?複製/粘貼這些東西,不要讓我們猜測。 3)爲了更快得到更好的幫助,請發佈[SSCCE](http://sscce.org/)。 4)爲什麼這是一個applet?他們是一個PITA來開發,並且對於新手來說太過先進。 – 2013-03-18 16:04:58
「歌曲無法解析」 – dhali 2013-03-18 16:07:58
在您的動作監聽器中,在if語句中,( ==「東西」)沒有任何意義。嘗試使用.equals()方法,String.equals(「Things」)。 –
Nixon
2013-03-18 16:18:49