title: How do I reference the "display" variable from my inner class, to use in the outer class in my JLabel
body: <p>I want to enter text into my fourth JPanel, and every time I hit enter to update the first JPanel with the text. I added a keylistener for the return key, it runs a function in the inner class AddSong, that function takes in an arraylist of text, and returns a string. I want to display that string on the JPanel in the first quadrent, but it doesn't work. Right now I believe it is removing the first JPanel, and not updating. I am very confused because this is my first encounter with key events as I am new to programming.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>public class MusicPlayer extends JFrame{
  
    private static final int WIDTH = 400;
    private static final int HEIGHT = 400;
    private JLabel songList,songPlaying,c;
    private JTextField enterSong;
    private AddSong input;
  
    public MusicPlayer(){
  
       //Text box enterSong, input passed to actionListener
       input = new AddSong();
       enterSong = new JTextField(10);
       enterSong.addActionListener(input);
  
       //Numbers the quadrents
       songList = new JLabel(input.printSongs(input.songList),SwingConstants.CENTER);
       songPlaying = new JLabel("2",SwingConstants.CENTER);
       c = new JLabel("c",SwingConstants.CENTER);
  
       //Makes and sets size of pane
       Container pane = getContentPane();
       pane.setLayout(new GridLayout(2,2));
  
       //Add JLabels to panes in the container
       pane.add(songList);
       pane.add(songPlaying);
       pane.add(c);
       pane.add(enterSong);
  
  
  
  
       //KeyListener - return
       addKeyListener(new KeyListener() {
          @Override
          public void keyPressed(KeyEvent ke){}
          @Override
          public void keyReleased(KeyEvent ke){}
          @Override
          public void keyTyped(KeyEvent ke){
             if(ke.getKeyCode()==KeyEvent.VK_ENTER){
                input.printSongs(input.songList);
             }
          }
       });
       add(songList);
       pack();
  
       setTitle("Andrew's Music Player");
       setSize(WIDTH,HEIGHT);
       setVisible(true);
       setDefaultCloseOperation(EXIT_ON_CLOSE);
  
    }
  
    public class AddSong implements ActionListener{
  
       //List of Songs
       ArrayList&lt;String&gt; songList = new ArrayList&lt;String&gt;();
       String display;
  
       public AddSong(){
          display = "";
       }
       public void actionPerformed(ActionEvent e){
  
          String song;
          //get the text
          song = enterSong.getText();
  
          //add current text string to list
          songList.add(song);
  
          //print songlist
          System.out.print(printSongs(songList));
  
       }
  
       public String printSongs(ArrayList&lt;String&gt; songList){
          display = "";
          for(int i = 0; i &lt; songList.size(); i++){
             display += songList.get(i) + "\n";
          }
          return display;
       }
    }
  
    public static void main(String args[]){
       MusicPlayer boi = new MusicPlayer();
    }
  </code></pre>
  
  <p>}</p>