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

public class Line02 extends JFrame {

  

  public Line02(String caption) {
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    setTitle(caption);
    this.getContentPane().add( new CCanvas(), 
      BorderLayout.CENTER );
    this.getContentPane().add( new JButton("Klick mich"), 
      BorderLayout.NORTH );
  }



 

    public static void main(String args[]) {
      Line02 f = new Line02("2. Linienbeispiel");
     	f.setSize(300,300);
    	f.setVisible(true);
    }


}



class CCanvas extends Canvas {

  private int count=0;

public void paint (Graphics g)
{
  count=count+1;
  System.out.println(count+". zeichnen");

  g.setColor(Color.YELLOW);
  g.fillRect(10,10, getWidth()-20, getHeight()-20 );

   g.setColor(Color.blue);
   int width,height;
    width = this.getWidth();
    height = this.getHeight();
    g.drawLine(0,0,width,height);

  


   g.setColor(Color.red);
  int x[] = new int[4];
  int y[] = new int[4];
  x[0] = 100;   y[0] = 100;
  x[1] = 200;   y[1] = 100;
  x[2] = 150;   y[2] = 80;
  x[3] = 170;   y[3] = 180;
  g.fillPolygon(x,y,4);

  //n = (int) (2/3*h);



}

 public void Ppaint (Graphics g)
  {
    int x = 80;
    Rectangle r = new Rectangle();
    g.getClipBounds(r);
    for (int i=0; i< r.getWidth()-50; i++) {
      x = (int) (4.0*Math.random());
      if (x==2)
      g.drawLine(i,40,i,(int) r.getHeight() );
      //x += 1+ 3*Math.random();
    }
  }

}




