title: for loop gets error "illegal start of type"
body: <p>so im trying to create a program in java which will create a 10 by 10 matrix, with each element displaying either a 1 or a 0 randomly. Here is what i have so far:</p>
  
  <pre><code>package random.matrix;
  
  import java.awt.GridLayout;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  
  class ex2 extends JFrame {
  
      class Random {
          GridLayout setLayout= new GridLayout(10, 10);
  
          for (int i = 0; i &lt; 10; i++) {
              int number = (int) (Math.random() * 2);
              String str = Integer.toString(number);
              add(new JLabel(str, JLabel.CENTER));
          }
      }
  
      public static void main(String[] args) {
          JFrame frame = new ex2();
          frame.setTitle("RandomMatrix");
          frame.setSize(400, 400);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setVisible(true);
      }
  }
  </code></pre>
  
  <p>As far as I can tell, this program should run perfectly. However, every time I try, it says something along the lines of "illegal start of type," referring specifically to the for loop line. Can anyone help me troubleshoot this? I've never encountered an error quite like this one.</p>