我想让我的高级项目在Java中的冠军选择像英雄联盟。我认为迄今为止我做得很好,但我陷入了一些困境。我想尝试打开一个JOptionPane播放声音文件。我整天都在做一些研究,但没有看到很多人在尝试。我通过JOptionPane看到了一些有关嘟嘟声的事情,但这就是它。有任何想法吗?JOptionPane中的音频文件
private class ButtonListener implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
String actionCommand = e.getActionCommand();
if (actionCommand.equals("Aatrox"))
{
playPopupMessageSound();
final ImageIcon icon = new ImageIcon("C:\\Users\\Owner\\Documents\\NetBeansProjects\\EventObjectWindow\\src\\eventobjectwindow\\Resources\\Aatrox.png");
JOptionPane.showMessageDialog(null, "You have selected Aatrox."+System.lineSeparator()+ "Aatrox is a legendary warrior, one of only five" +
"that remain of an ancient race known as the Darkin."+System.lineSeparator()+"He wields his massive blade with grace and poise, "+""
+ "slicing through legions in a style that is hypnotic to behold."+System.lineSeparator()+"With each foe felled, Aatrox's seemingly" +
"living blade drinks in their blood, empowering him and fueling his brutal, elegant campaign of slaughter." +System.lineSeparator()+
"Base stats:" +System.lineSeparator()+ "Health: 537.8 (+85 per level) Health Regen: 6.59 (+0.5 per level)"
+System.lineSeparator()+ "Attack Damage: 60.376 (+3.2 per level) Armor:24.384 (+3.8 per level)" +System.lineSeparator()+
"Attack Speed: 0.651 (+3% per level) Magic Resist: 32.1 (+1.25 per level)" +System.lineSeparator()+
"Movement Speed: 345", "Aatrox", JOptionPane.PLAIN_MESSAGE, icon);
}
else if (actionCommand.equals("Ahri"))
{
JOptionPane.showMessageDialog(null, "You have selected Ahri");
}
else if (actionCommand.equals("Akali"))
{
JOptionPane.showMessageDialog(null, "You have selected Akali");
}
else if (actionCommand.equals("Alistar"))
{
JOptionPane.showMessageDialog(null, "You have selected Alistar");
}
else if (actionCommand.equals("Amumu"))
{
JOptionPane.showMessageDialog(null, "You have selected Amumu");
}
else if (actionCommand.equals("Anivia"))
{
JOptionPane.showMessageDialog(null, "You have selected Anivia");
}
else if (actionCommand.equals("Annie"))
{
JOptionPane.showMessageDialog(null, "You have selected Annie");
}}
}
public static void main(String[] args)
{
EventObjectWindow em = new EventObjectWindow();
}
protected static void playPopupMessageSound() {
try (InputStream is = EventObjectWindow.class.getResourceAsStream("C:\\Users\\Owner\\Documents\\NetBeansProjects\\SrProjectLeague\\src\\srprojectleague\\Sounds\\Aatrox.wav")) {
try (AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(is)) {
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.start();
} catch (UnsupportedAudioFileException | LineUnavailableException ex) {
ex.printStackTrace();
}
} catch (IOException exp) {
exp.printStackTrace();
}}
public static class PlayPopupMessageSound implements Runnable {
@Override
public void run() {
playPopupMessageSound();
}
}}
写一个包装类更是把你需要一个'JOptionPane'的最常用参数,自己构造它并在显示之前播放声音 – MadProgrammer
我对Java很缺乏经验,所以你可能会详细阐述一下,对不起。 – blazelflack
我做过了,全部都在回答中 – MadProgrammer