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

abstract class f_x
{ abstract double func(double x);}



public class plotP extends JPanel
{ 
 int x[];
 int y[];
 double xmin;
 double xmax;
 int n;
 fb f;

 public plotP(f_x f,double xmini,double xmaxi,int width,int height)
 { 
   // height : height of the plot window;
   // width  : width of the plot window
   // xmin minimum x value
   // x maximum x value  
   xmin=xmini;
   xmax=xmaxi;
   n=100;
   x=new int[n];
   y=new int[n];
   double xd[]=new double[n];
   double yd[]=new double[n];
   double ymin=1.0e60;
   double ymax=-1.0e60;
   for(int i=0;i<n;i++) 
   {xd[i] = (xmax-xmin)*(double)i/(double)n;
   yd[i] =  f.func(xd[i]);
   if(yd[i]<ymin) ymin=yd[i];
   if(yd[i]>ymax) ymax=yd[i];
   }
  for(int i=0;i<n;i++)
  {x[i]=(int)(0.8*width*xd[i]/(xmax-xmin));
   y[i]=height/3+(int)(0.6*height*yd[i]/(ymax-ymin));	
  }
 }
 public void paintComponent(Graphics g)
 {
 Graphics2D g2=(Graphics2D)g;
 for(int i=0;i<x.length;i++)   
  {g2.drawString("x",x[i],y[i]);}
 }
 
}

