Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == Menu1) {
- System.out.println("Menu1 open");
- }
- if (e.getSource() == Mute) {
- if (!isFading) { // Only proceed if no fade operation is already in progress
- if (Mute.isSelected()) {
- System.out.println("sound off");
- fadeOutAudio(); // Fade out the audio when checkbox is selected
- } else {
- System.out.println("sound on");
- fadeInAudio(); // Fade in the audio when checkbox is deselected
- }
- }
- }
- }
- private void fadeOutAudio() {
- isFading = true;
- SwingUtilities.invokeLater(() -> {
- Mute.setEnabled(false);
- Mute.setDisabledIcon(new ImageIcon(getClass().getResource("/ressource/MuteIconON.png")));
- });
- new Thread(() -> {
- try {
- for (float volume = volumeControl.getValue(); volume > -80.0f; volume -= 0.15f) {
- volumeControl.setValue(volume);
- Thread.sleep(10);
- }
- clip.stop();
- } catch (InterruptedException e) {
- e.printStackTrace();
- } finally {
- SwingUtilities.invokeLater(() -> {
- Mute.setEnabled(true);
- Mute.setDisabledIcon(null);
- });
- isFading = false;
- }
- }).start();
- }
- private void fadeInAudio() {
- isFading = true;
- SwingUtilities.invokeLater(() -> {
- Mute.setEnabled(false);
- Mute.setDisabledIcon(Mute.getIcon());
- });
- new Thread(() -> {
- try {
- clip.start();
- //
- for (float volume = -80.0f; volume < 0.0f; volume += 0.30f) {
- volumeControl.setValue(volume);
- Thread.sleep(10);
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- } finally {
- SwingUtilities.invokeLater(() -> {
- Mute.setEnabled(true);
- Mute.setDisabledIcon(null);
- });
- isFading = false;
- }
- }).start();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement