title: Changing squares to rectangles in simple a Swing program
body: <p>I'm having some issues with what is probably a very simple problem in Java. I have written the following program that displays a 10x10 color matrix of squares whose colors are randomly generated and are randomly changed upon being clicked by a user in the window. However, if I wanted to change these squares to rectangles, for example, or any other shape how might I go about doing that? Is it even possible given the current code that I have? Thank you greatly for any help - sorry for the poor code indentation!</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.EventQueue;
  import java.awt.GridLayout;
  import java.awt.event.MouseAdapter;
  import java.awt.event.MouseEvent;
  import java.util.Random;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  
  public class ColorGrid extends JLabel {
  
      private static final int n = 10;
      private static final Random random = new Random();
  
      public ColorGrid() {
          this.setOpaque(true);
          this.setBackground(new Color(random.nextInt()));
          this.setPreferredSize(new Dimension(50, 50));
      }
  
      private void GridOutput() {
          JFrame f = new JFrame("ColorGrid Display Window");
          f.setLayout(new GridLayout(n, n));
          f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          for (int i = 0; i &lt; n * n; i++) {
              final ColorGrid label = new ColorGrid();
              label.addMouseListener(new MouseAdapter() {
  
                  public void mousePressed(MouseEvent e) {
                      label.setBackground(new Color(random.nextInt()));
                  }
              });
              f.add(label);
          }
          f.pack();
          f.setLocationRelativeTo(null);
          f.setVisible(true);
      }
  
      public static void main(String[] args) {
          EventQueue.invokeLater(new Runnable() {
  
              public void run() {
                  new ColorGrid().GridOutput();
              }
          });
      }
  }
  </code></pre>