😆 Close the player when closing the details dialog 💙

This commit is contained in:
Anas Elgarhy 2022-08-22 14:13:57 +02:00
parent d983c475a2
commit decfa29628

View file

@ -87,22 +87,30 @@ public class AyahDetailsDialog extends JDialog implements PlayerListener {
}
});
buttonCancel.addActionListener(l -> dispose());
buttonCancel.addActionListener(l -> close());
// call onCancel() when cross is clicked
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
close();
}
});
// call onCancel() on ESCAPE
contentPane.registerKeyboardAction(l -> dispose(),
contentPane.registerKeyboardAction(l -> close(),
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
}
private void close() {
if (isPlaying) {
audioPlayer.stop();
audioPlayer = null;
}
dispose();
}
private void playOrNot() {
if (autoPlayCheckBox.isSelected()) {
audioPlayer.stop();