1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
/**Importation des librairies*/
import java.io.*;
import java.net.*;
import java.util.*;
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.lang.*;
public class graphique extends JApplet
{
URL url = null;
URLConnection urlConnexion = null;
InputStream entree = null;
BufferedReader fluxEntree = null;
String valeur2 = new String("");
String ligne = new String("");
int indiceSeparateur = 0;
int nbreDeLigne = 0;
int lignesPassees = 0;
private Vector tableauValeury = new Vector();
private Vector tableauValeurx = new Vector();
int nbrePoint = 0;
double valxf ;
double valyf ;
double maxx ;
double maxy ;
double minx ;
double miny ;
double amaxy ;
double aminy ;
double amaxx ;
double aminx ;
int ce;
String source = "test.txt";
String valx = new String("");
String valy = new String("");
/**Méthode d'initialisation de l'applet - initialise les paramètres du graphique*/
public void init()
{
try
{
url = new URL(getCodeBase(),source);
urlConnexion = url.openConnection();
entree = urlConnexion.getInputStream();
fluxEntree = new BufferedReader(new InputStreamReader(entree));
//Lecture du fichier
while(fluxEntree.ready())
{
ligne = fluxEntree.readLine();
indiceSeparateur = ligne.indexOf(";");
valx = new String(ligne.substring(0,indiceSeparateur));
valy = new String(ligne.substring(indiceSeparateur + 1,ligne.lastIndexOf(";")));
tableauValeurx.addElement(valx);
tableauValeury.addElement(valy);
valxf = Double.parseDouble( valx ) ;
valyf = Double.parseDouble( valy ) ;
if (nbreDeLigne == 0){ minx = valxf ; maxx = valxf; miny = valyf ; maxy = valyf ; }
if (valxf > maxx){ maxx = valxf;}
if (valxf < minx){ minx = valxf;}
if (valyf > maxy){ maxy = valyf;}
if (valyf < miny){ miny = valyf;}
nbreDeLigne++;
ce = nbreDeLigne;
}
//Fermeture du fichier
fluxEntree.close();
//si problèmes de lecture du fichier
}
catch (FileNotFoundException fnfe)
{
System.out.println("fichier non trouvé");
}
catch (IOException ioe)
{
System.out.println("erreur d'E/S " + ioe.getMessage());
}
}//Fin de la méthode Init()
public void paint(Graphics g)
{
Enumeration listex = null;
Enumeration listey = null;
Float valeurPointx = null;
Float valeurPointy = null;
// tracage des axes
g.drawLine(40, 60, 40, 360);
g.setFont(new Font("Helvetica", Font.PLAIN, 22));
g.drawLine(40, 360, 1000, 360);
// tracage des points
nbreDeLigne = 1;
int ancienX = 0;
int ancienY = 0;
double ecarty;
double ecartx;
ecartx = amaxx-aminx;
ecarty = amaxy-aminy;
double rapporty ;
double rapportx ;
listex = tableauValeurx.elements();
listey = tableauValeury.elements();
while(listex.hasMoreElements())
{
g.drawLine(40+ancienX,60+ancienY,40+valxint,60+valyint);
ancienX = valxint;
ancienY = valyint;
nbreDeLigne ++ ;
g.setColor(Color.black);
}
} // fin tracage graph
}//fin de l'applet |
Partager