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

//List<Double> frameList =  new ArrayList<Double>();

// Derivation de la fenetre principale a parir fr JFRame
public class TraceurSuitePointFixe extends JFrame{
int i;
MonCanvasf MonCanv;
Vector<Double> V;
TraceurSuitePointFixe(String titre, MaFonction ff, Vector<Double> vv){
	super(titre);
	
	setLayout(new FlowLayout());
	i=0;
	MonCanv= new MonCanvasf(ff,vv,0);
	V=vv;
	add(MonCanv);
}

public void go(){
do{ 
MonCanv.repaint();
MonCanv.setj(i);
i++;
try {Thread.sleep(50);} 
catch (InterruptedException e) 
{e.printStackTrace();
}
} while(i<(V.size()-1));
}

public static void main(String[] args)
{ int nn=0;
Vector<Double> MonVect =  new Vector<Double>();	
MaFonction g =new MaFonction();
try { File fichier = new File("ficPointFixe.txt");       Scanner entree = new Scanner (fichier);
       entree.useLocale(Locale.US); 
while (entree.hasNextDouble()){ 
double a=0.0;
 a = entree.nextDouble();
System.out.println(a);MonVect.add(a); 
System.out.println("Ok ");      
int nb= MonVect.size();
//System.out.println("a= "+MonVect.elementAt(nn)+" nb= " +nb+"nn= "+nn);

nn++;
         }entree.close();
TraceurSuitePointFixe fenetre = new TraceurSuitePointFixe("Traceur de fonctions",g,MonVect);	  fenetre.pack();
	  fenetre.setSize(750,650);
	  fenetre.setResizable(true);
	  fenetre.setVisible(true);
	  fenetre.go();
}
catch(FileNotFoundException e)      {  System.err.println("Fichier non trouve");      }
}

}


class MonCanvasf extends Canvas {
  int j;
	MaFonction f;
	Vector<Double> V;
MonCanvasf( MaFonction ff, Vector<Double> vec, int jj){
	// arriere plan noir
	j=jj;
 setBackground(Color.white);
 setForeground(Color.green);
 	f=ff;
 	V=vec;}
 public void setj(int jj){ j=jj;}
public void paint (Graphics g) 
{ 
double x,y;
int xpos, ypos,xpos2;

g.translate(0,600);
// couleur de la fonction
g.setColor (new Color(255,255,0)); 
for(x=0.0; x<=1;x+=0.001){ 
y=f.calcul(x);
xpos=(int)(x*600);
ypos=(int)(-y*600);
g.fillOval(xpos,ypos,3,3);
}
g.setColor (new Color(0,255,0)); 
for(x=0.0; x<=1;x+=0.001){ 
y=x;
xpos=(int)(x*600);
ypos=(int)(-y*600);
g.fillOval(xpos,ypos,3,3);
}
g.setColor (new Color(0,0,255));
for(int i=0;i<=j;i++){ 
xpos=(int)(V.elementAt(i)*600);
ypos=(int)(V.elementAt(i+1)*600);
xpos2=(int)(V.elementAt(i+2)*600);
g.drawLine(xpos,-ypos,ypos,-ypos);
g.drawLine(ypos,-ypos,ypos,-xpos2);
}
}
// Dimension minimale du Canvas
public Dimension getMinimumSize() { 
return new Dimension(600,600);
}

public Dimension getPreferredSize() { 
return getMinimumSize();
}

} 
