title: How do I draw an array of graphics objects?
body: <p>So I have been pulling my hair out over this assignment for quite some time now, and I could really use some help. I have to create a rectangle graphics object in a super class, then extend that class into a subclass, that then draws 7 of said rectangles to draw a number like you would see on a calculator. I am  creating an array of rectangles in the subclass and trying to add them to a panel, however I keep getting errors for all the ways I try to add to the panel. Any help would be appreciated immensely.</p>
  
  <p>This is my super class</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  
  public class Bar extends JPanel {
  public Color myColor;
  Graphics g;
  int x;
  int y;
  int w;
  int h;
  
  public Bar(int newX, int newY, int newW, int newH) {
      x = newX;
      y = newY;
      w = newW;
      h = newH;
      super.paintComponent(g);
      g.setColor(getColor());
      g.fillRect(x, y, w, h);
  }
  
  public Color getColor() {
      return myColor;
  }
  }
  </code></pre>
  
  <p>and then my subclass</p>
  
  <pre><code>import java.awt.Color;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  
  public class LED extends Bar {
  public static Bar[] myLED;
  public static int number;
  public boolean isOn;
  
  
  public LED(Bar[] myLED) {
      super(10, 10, 15, 45);
      switch(number) {
          case 0: myLED[0] = new Bar(10, 10, 15, 45);
              isOn = true;
      }
  }
  
  public void setOn(boolean isOn) {
      if(isOn = true) {
          myColor = Color.GREEN;
      }
      else 
          myColor = Color.BLACK;
  }
  
  public static Bar[] getLED() {
      return myLED;
  }
  
  public static void main(String[] a) {
      JFrame window = new JFrame("Calculator");
      window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      window.setBounds(30, 30, 500, 500);
      JPanel panel = new JPanel();
      panel.add(myLED); //I'm getting an error on this line, as well as the one below this.
      window.getContentPane().add(myLED);//getContentPane().
      window.setVisible(true);
  }   
  }
  </code></pre>
  
  <p>Thanks.</p>