我使用netbeans,我有这个代码通过我播放音频剪辑
现在,我希望当用户按下JFrame上的下一个按钮时。框架配置另一个打开,剪辑停止。
这是我的代码:
这是按钮的mose发布事件:
Reg1 ro = new Reg1();
ro.setVisible(true);
clip.close();
this.dispose();
这主要是:
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
Welcome1 insta = new Welcome1();
insta.setVisible(true);
KeyListener s;
try {
AudioInputStream audio = AudioSystem.getAudioInputStream(new File("x.wav"));
Clip clip = AudioSystem.getClip();
clip.open(audio);
clip.start();
}
catch(UnsupportedAudioFileException uae) {
System.out.println(uae);
}
catch(IOException ioe) {
System.out.println(ioe);
}
catch(LineUnavailableException lua) {
System.out.println(lua);
}
}
});
它在行clip.close();
中显示错误我应该采取什么措施来消除错误? 因为我是新手,请解释你的答案。
错误是:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code
at Welcome1.jButton2MouseReleased(Welcome1.java:60)
at Welcome1.access$000(Welcome1.java:7)
at Welcome1$1.mouseReleased(Welcome1.java:29)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:273)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
答案 0 :(得分:0)
我猜在代码调用Clip
时Clip.close()
实例超出了范围。
这只是猜测,因为很难用代码片段说出来,堆栈跟踪的行号无法指示确切的代码行。请考虑将来发布SSCCE。
答案 1 :(得分:0)
我需要做的是初始化类下的变量,而不是在main下...就像那样简单