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

import java.awt.event.*;

public class Rect2 extends JFrame {


  public Rect2(String caption) {
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    setTitle(caption);
    this.getContentPane().add( new CCanvas(), 
       BorderLayout.CENTER );
  }


    public static void main(String args[]) {
      Rect2 f = new Rect2("Rect2");
     	f.setSize(500,400);
    	f.setVisible(true);
    }


}



class CCanvas extends Canvas {

  // Zeichnen von Rechtecken mit einem gemeinsamen "Mittelpunkten"
  // Breite = Hoehe * 2
 public void paint (Graphics g)
  {
    int x0, y0;  // Mittelpunkt
    int x, y;      // Mittelpunkt  links / oben
    int w, h;     // Breite Höhe
    int diff;
    x0 = 200;		 
    y0 = 200;		 
    diff = 50;

    g.setColor(Color.red);
    g.drawLine(x0-200,y0,x0+200,y0);
    g.drawLine(x0,y0-200,x0,y0+200);

    g.setColor(Color.blue);
    for (int i=0; i<10; i++) {
      x = x0 - diff;  // linker Ankerpunkt
      y = y0 - (diff >> 1);  // oberer Ankerpunkt  // SHR
      h = diff;
      w = diff << 1;		// SHL
      g.drawRect(x,y,w,h);
      diff += 10;
    }  // for

  }

}

