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

import java.awt.event.*;

public class Line04 extends JFrame {


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


     public static void main(String args[]) {
      Line04 f = new Line04("4. Linie");
     	f.setSize(700,500);
    	f.setVisible(true);
    }


}



class CCanvas extends Canvas {

  double f(double x) {
	return (Math.cos(x/5) + Math.sin(x/7) + 2) * getSize().height / 4;
 }

  public void paint (Graphics g)
  {
     g.setColor(Color.white);
     g.fillRect(25,25,
         getWidth()-50, getHeight()-50 );  // korrekter Rand
     g.setColor(Color.red);
     for (int x = 0 ; x < getSize().width ; x++) {
       g.drawLine(x,     (int) f(x),
                  x + 1, (int) f(x + 1));
     }
  }

}

