ok ci-dessous il y a un programme qui dessine des trais suivant les instructions dans la console d'entrée
par exemple f5r4f9; lui fera tracer une droite de 50 , tourner a droite de 40 degré et avancer de 90;
je voudrais que le programme trace 'en direct' sans attendre la fin
cad je pourrai faire f5 j'appuie sur entree il trace une droite ensuite je tape r4f9 et il continue
apparement le programme évoque paint() uniquement lorsque la boucle dans init() est terminée , c'est le probleme

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;
 
import javax.swing.JApplet;
 
 
 
public class test extends JApplet {
 
	static List<point> T=new ArrayList<point>();
 
	static double angle=-Math.PI/2;;
	static char carCourant;
 
	static int x,y;
 
    static void avancerCar() {
		try {
			carCourant = (char) System.in.read();
		} catch (java.io.IOException e) {
		}
	}
 
    static void lireExpression() throws InterruptedException {
    	if (carCourant=='f'){avancerCar();
    	int v=Integer.parseInt(carCourant+"");
    	x+=10*v*Math.cos(angle);
		y+=10*v*Math.sin(angle);
		T.add(new point(x,y));
		avancerCar();
    		}
    	if (carCourant=='r'){avancerCar();
    	int v=Integer.parseInt(carCourant+"");
    	angle+=10*v*Math.PI/180;
    	avancerCar();
    	}
    }
 
 
    /*
    
    static void lireExpression() throws InterruptedException{
    	
    	if (carCourant=='f'){avancerCar();lireDeplacement();}
    	if (carCourant=='r'){avancerCar();lireRotation();}
    	//else throw new Error (" Carac inattendu : ");
    }
    
    static void lireDeplacement() throws InterruptedException{
    	if (Character.isDigit(carCourant)){
    		x+=10*Integer.parseInt(carCourant+"")*Math.cos(angle);
    		y+=10*Integer.parseInt(carCourant+"")*Math.sin(angle);
    		T.add(new point(x,y));
    		avancerCar();}
    	//else throw new Error (" Carac inattendu : ");
    }
    
    static void lireRotation() throws InterruptedException{
    	if(Character.isDigit(carCourant)){angle+=10*Integer.parseInt(carCourant+"")*Math.PI/180;avancerCar();} 
    	//else throw new Error (" Carac inattendu : ");
    }
    */
 
    public void init(){   
 
    	avancerCar() ; // initialisation du car courant
    	T.add(new point(0,0));x=y=0;
    	while (carCourant != ';'){ 
			try {
				lireExpression();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
 
		}
		for (int i=0;i<T.size();i++){
			System.out.println(T.get(i).abs+".."+T.get(i).ord);
		}
 
    }
 
    public void paint(Graphics g){
    	g.drawString("bonjour", 100, 100);
    	if (T.size()>1){g.setColor(Color.blue);
			for (int i=0;i<T.size()-1;i++){
				g.drawLine(T.get(i).abs, T.get(i).ord, T.get(i+1).abs, T.get(i+1).ord);
			}
		}
    }
 
 
 
}
 class point{
	int abs,ord;
	public point(double a,double o){abs=(int) (100+a);ord=(int) (150+o);}
}