title: How to display output on textfield in java?
body: <p>I have this code again, and i am stuck on the part where I have to print out one of the numbers in the array to a swing textfield. I got it working once in awt, but i cant seem to get it working in swing. here is the code:</p>
  
  <pre><code>import java.awt.Container;
  import java.awt.FlowLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JTextField;
  import javax.swing.SwingUtilities;
  
  public class Koodibaasitäiustus extends JFrame {
  /**
   * 
   */
      private static final long serialVersionUID = 1L;
      private JTextField tfCount;
  
      public Koodibaasitäiustus() {
          Container cp = getContentPane();
          cp.setLayout(new FlowLayout());
          setResizable(false);
          cp.add(new JLabel("enter code"));
          tfCount = new JTextField("0", 10);
          tfCount.setEditable(true);
          cp.add(tfCount);
          JButton nupp = new JButton("get answer");
          cp.add(nupp);
          nupp.addActionListener(new ActionListener() {
  
              @Override
              public void actionPerformed(ActionEvent evt) {
                  int[] array;
                  array = new int[30];
                  array[0] = 111111;
                  array[1] = 888888;
                  array[2] = 333333;
                  array[3] = 555555;
                  array[4] = 111111;
                  array[5] = 643208;
                  array[6] = 643208;
                  array[7] = 643208;
                  array[8] = 643208;
                  array[9] = 643208;
                  array[10] = 643208;
                  array[11] = 643208;
                  array[12] = 643208;
                  array[13] = 643208;
                  array[14] = 643208;
                  array[15] = 643208;
                  array[16] = 643208;
                  array[17] = 643208;
                  array[18] = 643208;
                  array[19] = 643208;
                  array[20] = 643208;
                  array[21] = 643208;
                  array[22] = 643208;
                  array[23] = 643208;
                  array[24] = 643208;
                  array[25] = 643208;
                  array[26] = 643208;
                  array[27] = 643208;
                  array[28] = 643208;
                  array[29] = 643208;
                  array[30] = 643208;
                  int number = Integer.parseInt(tfCount.getText());
                  tfCount.setText(String.valueOf(array[number]));
  
              }
          });
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setTitle("Koodibaas");
          setSize(300, 100);
          setVisible(true);
          }
  
      public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
              @Override
              public void run() {
                  new Koodibaasitäiustus();
              }
          });
      }
  }
  </code></pre>