Bonjour,
j'essaye d'animer (à l'aide du Thread) un rectangle qui commence d'une ligne de mon tableau qui descend jusqu'à atteindre une valeur de Y, aprés qui bouge vers la gauche jusq'à atteindre une nouvelle position et aprés il remonte...en bref je veux assimiler le faite que les valeur de deux cases change...
voici le code de ma calsse Fenetre
et celui de mon panneau
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 import java.awt.BorderLayout; import java.awt.Color; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTable; public class Fenetre extends JFrame{ private Panneau pan = new Panneau(); JTable table=new JTable(); private JPanel container = new JPanel(); private int y ; private Thread t; public Fenetre(){ this.setTitle("Animation"); this.setSize(300, 300); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLocationRelativeTo(null); container.setBackground(Color.white); container.setLayout(new BorderLayout()); container.add(pan, BorderLayout.SOUTH); JPanel south = new JPanel(); String[] columnNames = {"","44","55","12","42","94","18","06","67"}; Object[][] data = { {"i=0"," 44"," 55"," 12"," 42"," 94"," 18"," 06"," 67"}, }; table = new JTable(data, columnNames); south.add(table); container.add(south, BorderLayout.NORTH); t = new Thread(new PlayAnimation()); t.start(); this.setContentPane(container); this.setVisible(true); } private void go(){ int x=pan.getPosX(); y = pan.getPosY(); while(y<100){ pan.setPosY(++y); pan.repaint(); if(y==90){while(x>pan.getPosX()){ pan.setPosX(--x); pan.repaint();} while(y!=0){ pan.setPosY(--y); pan.repaint();} } try { Thread.sleep(3); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } class PlayAnimation implements Runnable{ @Override public void run() { go(); } } }
j'arrive à faire visulaiser la 2 eme ligne de mon tableau , la premiere ne s'affiche pas , je ne sais pourquoi..
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 import java.awt.Color; import java.awt.Graphics; import javax.swing.JPanel; @SuppressWarnings("serial") public class Panneau extends JPanel { private int X=this.getHeight()/9; private int Y=0; public void paintComponent(Graphics g){ g.setColor(Color.white); g.fillRect(0, 0, this.getWidth(), this.getHeight()); g.drawRect(X*70,Y,X,10); g.setColor(Color.pink); g.fillRect(X*70,Y,X,10); g.drawString("6", X/4,5 ); } public int getPosX(){ return X; } public int getPosY(){ return Y; } public void setPosX(int x){ this.X=x; } public void setPosY(int y){ this.Y=y; } }
pour le rectangle je voi afficher un petit rectangle tout en bas de ma fenetre,sans aucune animation..
merci pour votre aide
NB:j'ai pas su ou je pourrais posté ma question alors je l'ai posté en Général..
Partager