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
| public class PanneauTrajet extends JPanel {
final int LARGPAN=500;
final int HAUTPAN=350;
String ligne;
String essai;
//String x;
int x=250;
/** Creates a new instance of PanneauTrajet */
public PanneauTrajet() {
setPreferredSize(new Dimension(LARGPAN,HAUTPAN));
setBackground(Color.blue);
try {
trajet();
} catch (IOException ex) {
ex.printStackTrace();
}
}
public void trajet() throws IOException {
String ligne;
char vitesse;
char temps;
char direction;
BufferedReader entree=new BufferedReader(new FileReader("trajet.txt"));
do{
ligne=entree.readLine();
if (ligne!=null) {
System.out.println(ligne);
vitesse=ligne.charAt(0);
temps=ligne.charAt(1);
direction=ligne.charAt(2);
System.out.println("vitesse: "+vitesse);
System.out.println("temps: "+temps);
System.out.println("direction: "+direction);
System.out.println("x="+x);
if (direction=='g') x=x-(temps*vitesse);
System.out.println("x= "+x);
if (direction=='d') x=x+(temps*vitesse);
}
}
while(ligne!=null);
entree.close();
repaint();
}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.drawLine(250,350,x,50);
}
} |
Partager