title: Follow up (merging single digit ints into one number)
body: <p>Here is the code with the GUI and revision to the for loop I created earlier. Every time the user pushes the one button I am hoping the textfield to reflect that the button was pressed.</p>
  
  <p>If the user presses the 1 button once: 1 is pushed onto the field.
  If the user presses the 1 button twice: 11 is pushed onto the field. 
  ... and so on.</p>
  
  <p>Instead, the program crashes the second time the button is pressed. Can somebody tell me what is going wrong?</p>
  
  <pre><code> import javax.swing.JFrame;
   import javax.swing.JPanel;
   import javax.swing.JButton;
   import javax.swing.JTextField;
  
   import java.awt.event.ActionListener;
   import java.awt.event.ActionEvent;
  
   import java.util.Arrays;
   import java.util.ArrayList;
   import java.lang.Math;
  
   public class poopy
   {
       public static void main(String[] args)
       {
          //frame width and height
         final int FRAME_WIDTH = 290;
         final int FRAME_HEIGHT = 210;
  
         //created frame and panel. Panel layout is taken away from the flow layout.
         JFrame myFrame = new JFrame();
         myFrame.setTitle("Simple Calculator");
         myFrame.setSize(FRAME_WIDTH,FRAME_HEIGHT);
         JPanel myPanel = new JPanel();
         myPanel.setLayout(null);
  
         //TextField on Simple Calculator
         final JTextField myText = new JTextField();
         myText.setSize(250,30);
         myText.setLocation(10,10);
  
         final JButton oneButton = new JButton("1");
         oneButton.setSize(50,50);
         oneButton.setLocation(10,102);
  
         //makes panel visible and close when the 'x' is hit
         myFrame.add(myPanel);
         myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         myFrame.setVisible(true);
  
         myPanel.add(oneButton);
         myPanel.add(myText);
  
         class CalculatorListener implements ActionListener
         {
             ArrayList&lt;Integer&gt; num = new ArrayList&lt;Integer&gt;();
             double x=0;
             int k = 0;
  
             public void actionPerformed(ActionEvent e)
             {
  
                 if(e.getSource() == oneButton)
                 {
                     num.add(1);
  
                     for(int i = num.size() -1; i&gt;=0; i--)
                     {
                         x = num.get(k) * Math.pow(10,i);
                         k=k+1;
                     }
  
                     myText.setText(" " + String.valueOf(x));
  
                 }
             }
         }
  
         //buttons are given life
         CalculatorListener myListener = new CalculatorListener();
         oneButton.addActionListener(myListener);
     }
  
  }
  </code></pre>