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
|
import java.awt.*;
import java.lang.*;
import java.awt.event.*;
import javax.swing.*;
public class testprojet extends JFrame implements ActionListener {
private Label largeur;
private TextField txtla;
private Label longueur;
private TextField txtlo;
private Display pan = new Display();
private JPanel container = new JPanel();
public JButton bouton = new JButton("Entrer");
int coo[][] = {
{0,50},{52,60},{65,100},{102,155},{160,200}, {202,250}
};
int i;
public testprojet() {
this.setTitle("Animation");
this.setSize(500, 500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
container.setBackground(Color.white);
container.setLayout(new BorderLayout());
container.add(pan, BorderLayout.CENTER);
JPanel north = new JPanel();
largeur = new Label("Start : ");
north.add(largeur);
txtla = new TextField(10);
north.add(txtla);
longueur = new Label("Stop : ");
north.add(longueur);
txtlo = new TextField(10);
north.add(txtlo);
north.add(bouton);
container.add(north, BorderLayout.NORTH);
bouton.addActionListener(this);
this.setContentPane(container);
this.setVisible(true);
}
public static void main(String[] args) {
new testprojet();
}
public void go(){
for(i=0; i<coo.length; i++) {
pan.getla(coo[i][0]);
pan.getlo(coo[i][1]);
pan.repaint();
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@Override
public void actionPerformed(ActionEvent evt) {
int numberla = Integer.parseInt(txtla.getText());
txtla.setText("");
int numberlo=Integer.parseInt(txtlo.getText());
txtlo.setText("");
go();
}
} |
Partager