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
|
import java.awt.GridBagLayout;
import javax.swing.JPanel;
import java.awt.FlowLayout;
import javax.swing.JTextArea;
import java.awt.Dimension;
import javax.swing.JScrollPane;
public class rr extends JPanel {
private JTextArea getJTextArea() {
if (jTextArea == null) {
jTextArea = new JTextArea();
jTextArea.setPreferredSize(new Dimension(220, 169));
jTextArea.setSize(new Dimension(220, 169));
}
return jTextArea;
}
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setPreferredSize(new Dimension(200, 164));
jScrollPane.setViewportView(getJTextArea());
}
return jScrollPane;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
char carCourant;
private JTextArea jTextArea = null;
private JScrollPane jScrollPane = null;
void avancerCar() {
try {
carCourant = (char) System.in.read();
} catch (java.io.IOException e) {
}
}
void lireExpression() throws InterruptedException {
if (carCourant=='f'){
jTextArea.append("forward");
avancerCar();repaint();
}
if (carCourant=='r'){
jTextArea.append("right");
avancerCar();
}
}
public rr() throws InterruptedException {
super();
initialize();
}
private void initialize() throws InterruptedException {
this.setSize(300, 200);
this.setLayout(new FlowLayout());
this.setVisible(true);
this.add(getJScrollPane(), null);
avancerCar() ; // initialisation du car courant
while (carCourant!=';'){
lireExpression();//repaint();
}
}
} |
Partager