title: Drawing Shape with ActionListener from Another Class
body: <p>In my program, I am gonna ask for number of rectangles in JPanel and add them into the frame with create button. I want to call rectangles from another class. But I can not see my rectangles. When I write same paint method in my main class, I can see rectangles but they appers when I run the program. I want them to appear with actionlistener. What am I doing wrong? Here is my classes;</p>
  
  <p>Rectangle Class:</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Graphics;
  import javax.swing.JFrame;
  public class Rectangle extends JFrame {
  
  public int getX() {
      return x;
  }
  public void setX(int x) {
      this.x = x;
  }
  public int getY() {
      return y;
  }
  public void setY(int y) {
      this.y = y;
  }
  public int getW() {
      return w;
  }
  public void setW(int w) {
      this.w = w;
  }
  public int getH() {
      return h;
  }
  public void setH(int h) {
      this.h = h;
  }
  public Color getC() {
      return c;
  }
  public void setC(Color c) {
      this.c = c;
  }
  private int x,y,w,h;
  private Color c;
  private asgn3 a3;
  public Rectangle() {
  
  
  }
  
  @Override
  public void paint(Graphics g) {
  super.paint(g); 
  
  g.fillRect(getX(), getY(), getW(), getH());
  g.setColor(Color.red);
  
  }
  
  }
  </code></pre>
  
  <p>My main JFrame class:</p>
  
  <pre><code>import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  import javax.swing.*;
  
  public class Example extends JFrame implements ActionListener {
  private JTextField recttext;
  private JButton create;
  private JLabel rectlabel,createlabel;
  private int seat a;
  private Rectangle[] rect;
  
  
  public Example() {
      setLayout(null);
  
      recttext = new JTextField();
      recttext.setSize(150, 40);
      recttext.setLocation(100, 40);
      add(recttext);
  
  
      rectlabel = new JLabel("Rectangle number");
      rectlabel.setSize(100, 20);
      rectlabel.setLocation(102, 20);
      add(rectlabel);
  
  
      create = new JButton("Create");
      create.setSize(70,30);
      create.setLocation(670, 20);
      add(create);
      create.addActionListener(this);
  
  
      setSize(800,800);
      setVisible(true);
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      setResizable(false);
  
  }
  public static void main(String[] args) {
  new Example();
  
  }
  @Override
  public void actionPerformed(ActionEvent e) {
  
  
     if(e.getSource().equals(create)) {
      a = Integer.parseInt(recttext.getText());
  
      rect = new Rectangle[a];
      for(int i=0;i&lt;a;i++) {
          rect[i]= new Rectangle();
  
      }   
  
      for(int i=1;i&lt;=a/10;i++) {
      for(int j=i;j&lt;11;j++) {
          rect[i-1].setX((getWidth()/(a/10))*i+20);
          rect[i-1].setY(100+j*50);
          rect[i-1].setW(100);
          rect[i-1].setH(50);
  
          repaint();
  
      }
      }
  
  }
  
  }
  }
  </code></pre>