Bonjour,
Je cherche à faire fonctionner une classe avec Runnable
mais je n'arrive pas à compiler en utilisant la méthode start()
qui devrait appartenir à la classe TestGraphic. Il y a quelque chose
qui m'échappe. En fait je cherche à lancer un affichage draw en utilisant
la boucle que je mets dans la méthode run.
D'avance merci de votre aide.

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
 
public class TestGraphic extends JFrame implements Runnable
{
	static int i;
	public JPanel test2; 
	Graphics lecontexteGr;
	public static void main (String[] args)
	{
 
	TestGraphic TG; 
	TG = new TestGraphic(); 
	TG.show();
	TG.start();
}
 
 
public TestGraphic ()
	{
 
	setSize (300,200);
	addWindowListener (new WindowAdapter() {
	public void windowClosing (WindowEvent événement)
		{ 
		System.exit(0);
		}
	});
 
	test2 = new lePanneau();
	getContentPane().add(test2);
 
	}
 
	public void run()
	{
	i=0;	
	while (i<100)
		{
		i++;
		update();
		}
	}
}
 
class lePanneau extends JPanel {
public void paintComponent (Graphics surface)
{
super.paintComponent(surface);
surface.drawRect(5, 5, 10, 10);
surface.drawArc(20, 20,200, 200, 10, 30);
}
 
}