title: Can i run a For Loop inside a GUI? As currently i am having problems with it therefore wanted to check it keep giving me IndexOutofBound
body: <p>As I am not sure on how to do it as the for loop in the GUI doesn't seem to run and it keeps giving the exception there i am at wits end.</p>
  
  <p>This is the code</p>
  
  <pre><code>public static class HelpWindow extends JDialog {
  
      JLabel label;
  
      public HelpWindow(JFrame frame) {
          super(frame, "Help", true);
          setLayout(new FlowLayout());
  
          label = new JLabel("Hey you");
          add(label);
      }
  }
  
  public static class AddQnA extends JDialog {
  
      JLabel label, label2, label3, label4;
      JTextField question, answer;
      JButton input, reset;
      JTextArea textarea;
  
      ArrayList&lt;String&gt; ques = new ArrayList&lt;&gt;();
      ArrayList&lt;String&gt; ans = new ArrayList&lt;&gt;();
  
      public AddQnA(JFrame frame) {
          super(frame, "Add Question &amp; Answer", true);
          setLayout(new FlowLayout());
  
          label = new JLabel("Question :");
          add(label);
  
          question = new JTextField(60);
          add(question);
  
          label2 = new JLabel("Answer   : ");
          add(label2);
  
          answer = new JTextField(60);
          add(answer);
  
          input = new JButton("Submit");
          add(input);
  
          reset = new JButton("Reset");
          add(reset);
  
          label3 = new JLabel("Please use the \"x\" on the top right to exit this section");
          add(label3);
  
          label4 = new JLabel("");
          add(label4);
  
          textarea = new JTextArea(10, 25);
          add(textarea);
          textarea.setEditable(false);
  
          Reset a = new Reset();
          reset.addActionListener(a);
  
          Submit b = new Submit();
          answer.addKeyListener(b);
  
          Submit c = new Submit();
          input.addActionListener(c);
      }
  
      public class Reset implements ActionListener {
  
          @Override
          public void actionPerformed(ActionEvent a) {
              question.setText("");
              answer.setText("");
          }
      }
  
      public class Submit implements KeyListener, ActionListener {
  
          @Override
          public void keyTyped(KeyEvent e) {
              // Not in use as of now therefore no method will be here
          }
  
          @Override
          public void keyPressed(KeyEvent b) {
              int keycode = b.getKeyCode();
              if (keycode == KeyEvent.VK_ENTER) {
                  ques.add(question.getText());
                  ans.add(answer.getText());
                  label4.setText("**Question &amp; Answer has been Added**");
                  textarea.append("Question:" + question.getText() + "\n");
                  textarea.append("Answer:" + answer.getText() + "\n\n");
                  question.setText("");
                  answer.setText("");
              }
          }
  
          @Override
          public void keyReleased(KeyEvent e) {
              // Not in use as of now therefore no method will be here
          }
  
          @Override
          public void actionPerformed(ActionEvent c) {
              ques.add(question.getText());
              ans.add(answer.getText());
              label4.setText("**Question &amp; Answer has been Added**");
         for (int i = 0; i &lt; ques.size(); i++) {
              if (ques.get(i) == null) {
                  textarea.append("There are no newly added questions or answers");
              } else {
                  textarea.append("Question: " + ques.get(i));
                  textarea.append("Answer: " + ans.get(i) + "\n");
              }
          }
              question.setText("");
              answer.setText("");
          }
  
      }
  }
  
  public static class DisplayQnA extends JDialog {
  
      JLabel label;
      JTextArea textarea;
      JMenuBar display;
      JMenu file;
      JMenuItem show;
  
      ArrayList&lt;String&gt; ques = new ArrayList&lt;&gt;();
      ArrayList&lt;String&gt; ans = new ArrayList&lt;&gt;();
  
      public DisplayQnA(JFrame frame) {
          super(frame, "Display Question &amp; Answer", true);
          setLayout(new FlowLayout());
  
          label = new JLabel("Displaying All Questions And Asnwers");
          add(label);
  
          AddQnA qa;
          qa = new AddQnA(frame);
          textarea = new JTextArea(10, 25);
          add(textarea);
          textarea.setEditable(false);
  
         for (int i = 0; i &lt; qa.ques.size(); i++) {
              if (qa.ques.get(i) == null) {
                  textarea.append("There are no newly added questions or answers");
              } else {
                  textarea.append("Question: " + qa.ques.get(i));
                  textarea.append("Answer: " + qa.ans.get(i) + "\n");
              }
          }
  
  
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>i am trying to get a input into my AddQnA arrays and than pull it from the DisplayQnA but it doesn't seemed to work at all. It just pops out a blank page, so i was also wondering is that as both Add and Display will pop up their own JFrames means when i cross Add JFrame will the information on the array stay or will it be deleted ?</p>