title: How to have an integer variable update as a result of a ChangeListener added to a JSlider
body: <p>Im having a bit of bother with a JSlider at the moment, Im fairly new to java so this may be easily rectified.</p>
  
  <p>I have a JSlider that looks like this here: 
  <a href="https://i.stack.imgur.com/g27LE.png" rel="nofollow noreferrer">JSlider Gui Image</a></p>
  
  <p>What I want to be able to do is have the "0" constantly update to the value of the JSlider. I have a ChangeListener added with .getValue() called upon the JSlider and set equal to an int variable as seen in this image: <a href="https://i.stack.imgur.com/tPQIu.png" rel="nofollow noreferrer">JSlider Code</a></p>
  
  <p>This int variable has been declared in the class so its not local to any methods, the System.out.println() proves that the ChangeListener is working as the value of the JSlider is constantly updated and printed in the console however the int variable does not seem to hold its value outside of this ChangeListener and therefore will not display the current value in the border where I want it to.</p>
  
  <p>Does anyone have any clue on how to resolve this?</p>
  
  <p>All Relevant code is here:    </p>
  
  <pre><code>JPanel sectorSlider = new JPanel();
  
  sectorSlider.setLayout(new BorderLayout());
  TitledBorder sectorSliderBorder;
  
  final int sectorNumberMin = 0;
  final int sectorNumberMax = 50;
  final int sectorNumberInitial = 12;
          JSlider sectorNumberSlider = new JSlider(JSlider.HORIZONTAL,
          sectorNumberMin, sectorNumberMax, sectorNumberInitial);
         sectorNumberSlider.setMajorTickSpacing(10);
  sectorNumberSlider.setMinorTickSpacing(5);
  sectorNumberSlider.setPaintTicks(true);
  sectorNumberSlider.setPaintLabels(true);
  
  sectorNumberSlider.addChangeListener(new ChangeListener() {
      @Override
      public void stateChanged(ChangeEvent event) {
          sectorValue = sectorNumberSlider.getValue();
          System.out.println(sectorValue);
      }
  });
  
  sectorSliderBorder = BorderFactory.createTitledBorder(blackline, "Number of Sectors: " +sectorValue);
  
  sectorSliderBorder.setTitleJustification(TitledBorder.CENTER);
  sectorSlider.setBorder(sectorSliderBorder);
  sectorSlider.add(sectorNumberSlider);
  </code></pre>