import java.awt.*;
import javax.swing.*;

class AA extends JFrame{
int x2;
int y2;
int x;
int y;

public AA(int x, int y, int x2, int y2) {
 this.x = x;
 this.y = y;
 this.x2 = x2;
 this.y2 = y2;
 }

 public void paint(Graphics g) {
  g.setColor(new Color(0,0,0));
  g.fillRect(x,y,x2,x2);
 }

}//끝

public class nemo extends JFrame{
 public static void main(String[] args) {
 new nemo();
 }

 public nemo() {
  //-------- 창틀 만들기 -------
  super("각종사각형");
  setBounds(200,200,1000,500);
  setVisible(true);
  setLayout(new FlowLayout());    

 

 //-------- 여러 사각형 그리기  -------

  AA 사각형1 = new AA(10,10,10,200);
  AA 사각형2 = new AA(30,10,10,100);
  AA 사각형3 = new AA(60,10,10,150);
  AA 사각형4 = new AA(90,10,10,250);
  AA 사각형5 = new AA(120,10,10,200);

 }

}//끝

 

 

 

 

예상대로라면 사각형 네개가 그려져야 하는데 윈도창만 달랑 나옴.

paint(Graphics g) <--- 이 부분을 nemo 클래스에 적으면 사각형이 하나만 나옴.

의문점. AA나 nemo 나 extends 상속을 받은 건 똑 같은데 어째서 AA클래스에  적었을 때는 실행이 되지 않는거지?

뭘 빠뜨렸나?