title: Simple Java: How to create a mute and unmute button in the background?
body: <p>I'm working on a project that constantly changes pages and repaints the page and i need a mute and unmute to have music playing in the background. My problem is whenever it changes pages and repaints and stuff the music resets and stops. I'm making it so whenever the mouse is pressed on the mute/unmute button then the music will either play or stop depending on if it is muted or not.</p>
  
  <p>Anyone have any simple coding i could use that will create a mute/unmute button to play music in the background that won't be interrupted every time the page changes?</p>
  
  <p>I am making this on java on eclipse on an Applet.</p>
  
  <p>Please dumb it down a bit for me because i'm kind of new to java so i don't know too much. Thanks.</p>
  
  <p>Here is some code where the page changes:</p>
  
  <pre><code>public void paint(Graphics g){   
      switch (roomPage){
      case 0: homeScreen(g); break;
      case 1: instructionsPage(g); break;
      case 2: startPage(g); break;
      }
  }
  </code></pre>
  
  <p>and here is some code on what i want to happen:</p>
  
  <pre><code>public void mousePressed(MouseEvent me) {
      if (xPos &gt; 0 &amp;&amp; xPos &lt; 0+64 &amp;&amp; yPos &gt;0 &amp;&amp;  
              yPos &lt; 0+64){
          if(soundMuted == false){
           //since it's not muted and it is clicked then the music will change
           //to "soundMuted = true" and the music will stop
           soundMuted = true;
          }
          else {
          //since it will be changing to "soundMuted = false" the music will
          //start again
          soundMuted = false;
          }
      }
  }
  </code></pre>
  
  <p>The problem with ^ this though is that whenever i use it and it goes to a different page it for some reason resets it back to it's default state which is false. I just want an example to simplify a mute/unmute button that can play uninterrupted in the background unless the button is clicked.</p>