Advertisement
Guest User

Untitled

a guest
Mar 19th, 2025
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. public void actionPerformed(ActionEvent e) {
  2. if (e.getSource() == Menu1) {
  3. System.out.println("Menu1 open");
  4. }
  5.  
  6. if (e.getSource() == Mute) {
  7. if (!isFading) { // Only proceed if no fade operation is already in progress
  8. if (Mute.isSelected()) {
  9. System.out.println("sound off");
  10. fadeOutAudio(); // Fade out the audio when checkbox is selected
  11. } else {
  12. System.out.println("sound on");
  13. fadeInAudio(); // Fade in the audio when checkbox is deselected
  14. }
  15. }
  16. }
  17. }
  18.  
  19. private void fadeOutAudio() {
  20. isFading = true;
  21. SwingUtilities.invokeLater(() -> {
  22. Mute.setEnabled(false);
  23. Mute.setDisabledIcon(new ImageIcon(getClass().getResource("/ressource/MuteIconON.png")));
  24. });
  25. new Thread(() -> {
  26. try {
  27. for (float volume = volumeControl.getValue(); volume > -80.0f; volume -= 0.15f) {
  28. volumeControl.setValue(volume);
  29. Thread.sleep(10);
  30. }
  31. clip.stop();
  32. } catch (InterruptedException e) {
  33. e.printStackTrace();
  34. } finally {
  35.  
  36. SwingUtilities.invokeLater(() -> {
  37. Mute.setEnabled(true);
  38. Mute.setDisabledIcon(null);
  39. });
  40. isFading = false;
  41. }
  42. }).start();
  43. }
  44.  
  45. private void fadeInAudio() {
  46. isFading = true;
  47. SwingUtilities.invokeLater(() -> {
  48. Mute.setEnabled(false);
  49. Mute.setDisabledIcon(Mute.getIcon());
  50. });
  51. new Thread(() -> {
  52. try {
  53. clip.start();
  54. //
  55. for (float volume = -80.0f; volume < 0.0f; volume += 0.30f) {
  56. volumeControl.setValue(volume);
  57. Thread.sleep(10);
  58. }
  59. } catch (InterruptedException e) {
  60. e.printStackTrace();
  61. } finally {
  62.  
  63. SwingUtilities.invokeLater(() -> {
  64. Mute.setEnabled(true);
  65. Mute.setDisabledIcon(null);
  66. });
  67. isFading = false;
  68. }
  69. }).start();
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement