Bonjour,
Je suis en train de développer un petit truc en java. J'ai 3 classes Workshop, Robots et Rectangle.
Mon probléme est au niveau du rafraichissement de la JFrame hérité par la classe Workshop. Je dois dessiné la position de mes robot.

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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
 
import java.awt.*;
import java.util.Vector;
import javax.swing.*;
 
public class Workshop extends JFrame{
 
	private static final long serialVersionUID = 6465512783460919170L;
	private Vector<Rectangle> v_rect;
	private Vector<Robots> v_robots;
	private Robots r2d2;
	private Graphics2D gc;
	private int goalx;
	private int goaly;
 
	public Workshop(){
		super("Robots Explorer");
		this.setBackground(Color.white);
		this.setBounds(-10, -10, 300, 300);
		this.setVisible(true);
		this.setExtendedState(300);
		this.setResizable(false);
 
		createRobots();
		System.out.println("workshop");
	}
 
	public void createRobots(){	
			r2d2 = new Robots( 45, 45, Color.yellow);
			Thread t = new Thread(r2d2);
			t.start();
			v_robots = new Vector<Robots>();
			v_robots.add(r2d2);
	}
 
	public void createEnv( int width_frame, int heigth_frame ){
		int id = 0;
		this.v_rect = new Vector<Rectangle>();
		boolean ob = false;
 
		try{
 
			for( int x = 0; x<= 300; x+=30 ){
				for(int y= 20;y<=270; y+=30 ){
 
					id++;	
					gc.drawRect(x, y, width_frame/10, heigth_frame/10);
					Rectangle rect = new Rectangle( id, ob, x, y, width_frame/10, heigth_frame/10);
					v_rect.add(rect);	
 
				}
			}
 
			gc.fillRect( 60, 80, 90, 30); 
			gc.fillRect( 240, 20, 30, 60); 
			gc.fillRect( 150, 230, 120, 30); 
			gc.fillRect( 120, 170, 30, 90); 
 
			for( int i=0;i<=(v_rect.size()-1); i++){
 
				Rectangle _rect = v_rect.get(i);
				int y = _rect.getPos_y();
				int x = _rect.getPos_x();
 
				if( y == 80 && x >= 60 && x < 150 ){
					_rect.setObstacle(true);
				}
 
				if( x == 240 && y >= 20 && y < 80 ){
					_rect.setObstacle(true);
				}
 
				if( y == 230 && x >= 150 && x < 270 ){
					_rect.setObstacle(true);
				}
 
				if( x == 120 && y >= 170 && y < 260 ){
					_rect.setObstacle(true);
				}
			}
 
		}catch(Exception e){
			System.out.println( e.toString() +" => " +e.getMessage());
		}
 
	}
 
	public void putGoal(){
 
		Rectangle rect;
		int rect_x, rect_y;
		this.goalx = 190;
		this.goaly = 190;
 
 
		for( int i=0;i<=(v_rect.size()-1); i++ ){
 
			rect = v_rect.get(i);
			rect_x = rect.getPos_x();
			rect_y = rect.getPos_y();
 
			if( rect_x <= goalx && rect_y <= goaly && rect_x+30 >= goalx && rect_y+30 >= goaly ){
 
				gc.setColor(Color.red);
				gc.fillArc((rect_x+5), (rect_y+5), 20, 20, 0, 360);
				gc.setColor(Color.black);	
				rect.setGoal(true);
			}	
		}
	}
 
	public void paint(Graphics g) {
		gc = (Graphics2D) g;
		createEnv( 300, 300);
		putGoal();
		System.out.println("paint");
	}
 
	public void paintRobots(){
 
		for( int i=0; i <= (v_robots.size()-1); i++ ){
			int x = v_robots.get(i).getPos_x();
			int y = v_robots.get(i).getPos_y();
			Color c = v_robots.get(i).getColor();
			System.out.println(x+ " "+y+" "+ " "+c.toString());
			gc.setColor(c);
			gc.fillArc( x, y, 20, 20, 0, 360);
		}
		gc.setColor(Color.black);
 
		System.out.println("paint robots");
	}
 
	public static void main(String[] args) throws InterruptedException {
 
		Workshop ws = new Workshop();
 
		while(ws.EXIT_ON_CLOSE != 1){
			ws.paint( ws.gc );
			ws.paintRobots();
			Thread.sleep(1000);
		}
 
	}
 
}
Mais ca marche.. et je vois pas trop pourquoi.
Si quelqu'un pourrait m'aider à ce sujet
Merci