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
| public class Simulation extends Thread {
// temps simule a chaque thread 10s (A chaque étape)
public static final double TEMPS = 10;
// applet attachée à cette simulation
private AppletPh2 applet;
// la simulation est-elle en marche ?
private boolean marche ;
// la liste qui contient l'ensemble des simulations
private ArrayList<EtapeSimulation> liste;
// le pas de simulation
private int pasDeSimulation ;
private boolean tourne;
/**
* Instanciation de la classe.
*/
public Simulation(AppletPh2 app){
applet = app;
// on initialise les variables
marche = false ; // à la pause marche = true
tourne =true;
}
/**
* @see java.lang.Runnable#run()
*/
public void run(){
long heureDepartPas;
long tempsDePas;
while(tourne){
if(marche){ //marche= true à la pause aussi
heureDepartPas = System.currentTimeMillis();
FenetreFichier ff = applet.getFenetreFichier();
if( ff.getLireFichier() ){
ff.analyseFichierLigne();
}
for(int i=0; i<liste.size(); i++){
EtapeSimulation tmp = liste.get(i);
tmp.simulerUnPas();
//System.out.println(j++);
}
// on affiche les changements à l'ecran
applet.repaint();
// Afficher les points pour cette abcisse sur le graphe pompe
if (applet.getFenetreGraphe().getGraphePompe().getGraphics() != null) {
applet.getFenetreGraphe().getGraphePompe().afficherPoint();
}
// On affiche les points des courbes
if (applet.getFenetreGraphe().getGraphePh().getGraphics() != null) {
Graphics g=applet.getFenetreGraphe().getGraphePh().getGraphics();
applet.getFenetreGraphe().getGraphePh().afficherPoint();
}
// On respecte le pas
tempsDePas = System.currentTimeMillis() - heureDepartPas;
if (tempsDePas < this.pasDeSimulation) {
// La tache est endormi dans le temps restant pour respecter le pas
try {
Thread.sleep(this.pasDeSimulation - tempsDePas);
} catch (InterruptedException e) {}
}
}
}
} |
Partager