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

public class nikolaus1 extends JFrame {
    
    /** Creates a new instance of grafik1 */
  public nikolaus1() {
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    this.getContentPane().add( new CCanvas(), BorderLayout.CENTER );
  }

    
    
    public static void main(String[] args) {
        nikolaus1 f = new nikolaus1();
        f.setSize(600,300);
        f.setVisible(true);
    }
    
}


class CCanvas extends Canvas {

  public void paint (Graphics g)
  {
      int w = getWidth();
      int h = getHeight()-80;
      int n, top, left;
      
      // Löschen des Bildschirms
      g.setColor(Color.WHITE);
      g.fillRect(0,0, getWidth(), getHeight() );
      
      // zentrieren
      // 3 Fälle  Quadrat,  horizontaler  Zylinder, Vertikaler Zylinder
      if (w*1.5 < h) 
          n = w;  // horizontaler  Zylinder
      else
          n = (int) (h/1.5);  // senkrechter  Zylinder
    
      top = 50 + n/2;
      left = ( getWidth()-n) >> 1;
      
      g.setColor(Color.BLUE);
      g.drawRect(left, top, n,n);
      
      // Dach
  /*    Graphics2D g2 = (Graphics2D) g;
      g2.setStroke( new BasicStroke(4.0f) );
   */
      Graphics2D g2 = (Graphics2D) g;
      float [] dashs = {10.0f, 15.0f};  // Länge Strich , Pause
      // BasicStroke(float width, int cap, int join, float miterlimit, float[] dash, float dash_phase)
      //  1.0f = miterlimit
      g2.setStroke( new BasicStroke(3.0f,  BasicStroke.CAP_BUTT,   BasicStroke.JOIN_MITER, 1.0f, dashs, 0.0f ) );
      
      g.setColor(Color.BLUE);
      g.drawLine(left,top,            left+n/2, top-n/2 );
      g.drawLine(left+n/2, top-n/2,   left+n, top);
      
      // Diagonale
      Graphics2D g3 = (Graphics2D) g;
      float [] dashs3 = {10.0f, 5.0f, 4.0f, 5.0f};  // Länge Strich , Pause
      // BasicStroke(float width, int cap, int join, float miterlimit, float[] dash, float dash_phase)
      //  1.0f = miterlimit
      g3.setStroke( new BasicStroke(3.0f,  BasicStroke.CAP_BUTT,   BasicStroke.JOIN_MITER, 1.0f, dashs3, 0.0f ) );
      g.setColor( new Color(255,0,255)  );
      g.drawLine(left,top,            left+n, top+n );
      g.drawLine(left, top+n,         left+n, top);
  
      // Farbiges Dach
      
     g.setColor(Color.RED);
     int x[] = new int[3];
     int y[] = new int[3];
      x[0] = left;   y[0] = top;
      x[1] = left+n/2;   y[1] = top-n/2;
      x[2] = left+n;   y[2] = top;
    g.fillPolygon(x,y,3);
  
    
    // Interne Kreise
    Graphics2D g4 = (Graphics2D) g;
    g4.setStroke( new BasicStroke(2.0f) );
    g.setColor(Color.CYAN);
    g.drawOval(left,top+n/4,n/2, n/2);
    g.drawOval(left+n/2,top+n/4,n/2, n/2);
    g.setColor(Color.GREEN);
    g.drawOval(left+n/4,top,n/2, n/2);
    g.drawOval(left+n/4,top+n/2,n/2, n/2);
  
    
    // Text
    g.setColor(new Color(200,200,00));
    String s = "x: "+Integer.toString(left)+"  "+"y: "+Integer.toString(top);
    g.drawString(s, left-70,top);
  
    s = "x: "+Integer.toString(left)+"  "+"y: "+Integer.toString(top+n);
    g.drawString(s, left-70,top+n);
  
    s = "x: "+Integer.toString(left+n)+"  "+"y: "+Integer.toString(top);
    g.drawString(s, left+n+10,top);
    
    s = "x: "+Integer.toString(left+n)+"  "+"y: "+Integer.toString(top+n);
    g.drawString(s, left+n+10,top+n);
    
    
    
  }  // paint
  
}


