Zeichnung einfache Rechtecke auf ein Jframe in java

Ich bin Verlängerung JFrame so:

public GameFrame() {
    this.setBounds(30, 30, 500, 500);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    initializeSquares();
}

private void initializeSquares(){
    for(int i = 0; i < 5; i++){
        this.getContentPane().add(new Square(i*10, i*10, 100, 100));
    }
    this.setVisible(true);
}

Jedoch nur ein Quadrat gezeichnet wird, auf dem Bildschirm, weiß jemand warum?

auch Meine Square-Klasse sieht wie folgt aus:

private int x;
private int y;
private int width;
private int height;
public Square(int x, int y, int width, int height){
    this.x = x;
    this.y = y;
    this.width = width;
    this.height = height;
}

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawRect(x, y, width, height);
}
InformationsquelleAutor wfbarksdale | 2012-03-15
Schreibe einen Kommentar