JAVA 我的JFrame类实现了窗口监听
JAVA我的JFrame类实现了窗口监听,类里面有一个创建了一个线程来播放因为,窗口打开时线程开始即播放音乐,我希望窗口关闭时线程停止即音乐停止,可为何实现不了?代码如下...
JAVA 我的JFrame类实现了窗口监听,类里面有一个创建了一个线程来播放因为,窗口打开时线程开始即播放音乐,我希望窗口关闭时线程停止即音乐停止,可为何实现不了?代码如下public class TankWar extends JFrame implements WindowListener {
MyPanel mp = null
Music s = new Music("file:///06.EVERYWHERE YOU GO.MP3");
public TankWar() {
mp = new MyPanel()
this.getContentPane().add(BorderLayout.CENTER, mp);
this.addWindowListener(this);
this.addKeyListener(mp);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setSize(850, 685);
this.setVisible(true);
}
public static void main(String[] args) {
TankWar a = new TankWar();
}
public void windowActivated(WindowEvent e) {
}
public void windowClosed(WindowEvent e) {
s.stop();
}
public void windowClosing(WindowEvent e) {
}
public void windowDeactivated(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowOpened(WindowEvent e) {
s.start();
}
} 展开
MyPanel mp = null
Music s = new Music("file:///06.EVERYWHERE YOU GO.MP3");
public TankWar() {
mp = new MyPanel()
this.getContentPane().add(BorderLayout.CENTER, mp);
this.addWindowListener(this);
this.addKeyListener(mp);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setSize(850, 685);
this.setVisible(true);
}
public static void main(String[] args) {
TankWar a = new TankWar();
}
public void windowActivated(WindowEvent e) {
}
public void windowClosed(WindowEvent e) {
s.stop();
}
public void windowClosing(WindowEvent e) {
}
public void windowDeactivated(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowOpened(WindowEvent e) {
s.start();
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询