conflit static <> repaint()
Bonjour
voici ma classe
Code:
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
|
public class graph extends JPanel{
static List<point> T=new ArrayList<point>();
static double angle;
static void avancerCar() {
try {
carCourant = (char) System.in.read();
} catch (java.io.IOException e) {
}
}
static void lireExpression() throws InterruptedException{
if (carCourant=='f'){avancerCar();lireDeplacement();}
else if (carCourant=='r'){avancerCar();lireRotation();}
else throw new Error (" Carac inattendu : ");
}
static void lireDeplacement() throws InterruptedException{
if (Character.isDigit(carCourant)){T.add(new point(carCourant*Math.cos(angle),carCourant*Math.sin(angle)));avancerCar();}
else throw new Error (" Carac inattendu : ");
}
static void lireRotation() throws InterruptedException{
if(Character.isDigit(carCourant)){angle+=(int)(carCourant);avancerCar();}
else throw new Error (" Carac inattendu : ");
}
public void paint(Graphics g){
g.drawString("bonjour", 100, 100);
if (T.size()>1){
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).abs, T.get(i+1).ord-T.get(i).ord);
}
}
}
public static void main(String[] args) throws InterruptedException {
lex2.avancerCar () ;
avancerCar() ; // initialisation du car courant
T.add(new point(0,0));
while (carCourant != ';'){
lireExpression();
}
for (int i=0;i<T.size();i++){
System.out.println(T.get(i).abs+".."+T.get(i).ord);
}
}
}
class point{
int abs,ord;
public point(double a,double o){abs=(int) (250+a);ord=(int) (250+o);}
} |
à tester avec f4r5f5 dans la console d'entrée
par exemple
Le but est que ça s'actualise au fur et a mesure qu'on ajoute des points
mais impossible de glisser des repaint() dans les méthodes qui sont STATIC
comment faire SVP?