title: How do I make variables accessible everywhere?
body: <p>I am using java swing and I have tried using new text as a parameter but I am not sure how, there is also the fact that I have &quot;});&quot; which is completely messed up but it works, and i tried fixing it and it doesn't work</p>
  <p>this code is inside my main</p>
  <pre><code>public String newText = &quot;&quot;;
  
  a.addActionListener(new ActionListener() {
  
    public void actionPerformed(ActionEvent ae) {
      JFrame popup = new JFrame(&quot;Choose...&quot;);
      popup.setSize(250,250);
      popup.setLayout(null);
      popup.setVisible(true);
      JButton o=new JButton(&quot;o&quot;);
      o.setBounds(25,75,100,100); 
      popup.add(o);
      o.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae, String newText){
          newText = &quot;O&quot;;
        }
      });
      JButton x=new JButton(&quot;x&quot;); 
      x.setBounds(125,75,100,100);  
      popup.add(x);
      if (!newText.equals(&quot;&quot;))
          a.setText(newText);
    }
  });
  
  </code></pre>