title: Changing Image on click with Java/Swing Jframe
body: <p>OK there are similar questions out there, but the problem I have is specific.</p>
  
  <p>What I have is a simple jFrame with 3 buttons. When one of the buttons is pressed it will calculate the BPM of a song. It will also edit a StringBuilder object to create a url path for the image. This part of the out put is fine here is my console output on press.</p>
  
  <pre><code>104.9      //Bpm of Song
  One        //String representation of first char in array
  Zero       //String representation of Second char in array
  Four       //String representation of Third char in array
  Nine       //String representation of Fifth char in array
  res/1.png  // 
  res/0.png  // New Url paths
  res/4.png  //
  res/9.png  //
  </code></pre>
  
  <p>The problem I have is in the code.</p>
  
  <pre><code>JButton tapButton = new JButton("Tap");
      tapButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
  
              MathFunctions.tapBPM();
              ArrayComparison.stringCharArrays();
  
              String urlLocationOne = (ArrayComparison.urlLocationOneBuild.toString());
              String urlLocationTwo = (ArrayComparison.urlLocationTwoBuild.toString());
              String urlLocationThree = (ArrayComparison.urlLocationThreeBuild.toString());
              String urlLocationFive = (ArrayComparison.urlLocationFiveBuild.toString());
  
          }
      });
      tapButton.setBounds(100, 150, 120, 45);
      contentPane.add(tapButton);
  </code></pre>
  
  <p>urlLocation[number]Build is a StringBuilder object. On each click it checks the template url, deletes the number and replaces it (this bit we know works fine). The problem comes with the images. If I create a new image in the tapButton ActionEvent it doesn't load, I have to create the image as it's own JLabel (outside of the button)</p>
  
  <p>(here is the code for the JLabel (there are five of these i'll show you only one))</p>
  
  <pre><code>JLabel locationOne = new JLabel("Image 1");
  locationOne.setBackground(Color.WHITE); 
  locationOne.setIcon(new ImageIcon(urlLocationOne));   //urlLocationOne not available outside of button
  locationOne.setBounds(84, 38, 66, 100);
  contentPane.add(locationOne);
  </code></pre>
  
  <p>so if the imageIcon is created inside the button it doesn't work, if it's created outside the button, it is outside of "urlLocationOne"'s scope and if I create a field I create an immutable string that only changes inside the tap button and when called outside the tapButton method it displays the original string. What is the best way to place the images so that the image's respond the path changes on each click. (remember the paths are changing I just can't get the ImageIcon JLabel to 'hear' the change.)</p>