Je n'arrive pas a "voir" mes boutons quand je lance cette JFrame , un oeil attentif peu t i me dire mon erreur ?
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
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MediaTracker;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
 
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
 
 
public class Panel2 extends JPanel {
 
	Graphics g2;
	MediaTracker tracker;
	File file;
	JButton marche,arret;
	ImageIO io;
	ImageIcon image;
	BufferedImage input;
 
	int p2512[] ={0,1,0,0,1,0,1,0,0,1,1,1};
 
 
	public Panel2() throws IOException
	{
		marche = new JButton("Reprendre");
		marche.setLocation(1, 1);
		this.add(marche);
 
 
 
		arret = new JButton("Arreter");
		arret.setLocation(1, 10);
		this.add(arret);
 
		file = new File("2512.jpg");
	    input = ImageIO.read(file);
 
}
 
	 public void paintComponent(Graphics g) 
	 {
		 //super.paintComponent(g);
 
//		initialisation de l’image
		 Graphics2D g2d2 = input.createGraphics();
		int j=0;
		 for(int i=0;i<6;i++)
		 	{
			if(p2512[j]==1)
			g2d2.setColor(Color.GREEN);
			else
			g2d2.setColor(Color.red);
 
			g2d2.fillRect(292+16*i, 44, 10, 10);
			System.out.println(j);
			j++;
 
		 	}
 
		 for(int h=0;h<6;h++)
		 	{
			 if(p2512[j]==1)
					g2d2.setColor(Color.GREEN);
			else
					g2d2.setColor(Color.red);
 
 
			g2d2.fillRect(292+16*h, 62, 10, 10);
			System.out.println(j);
			j++;
		 	}
 
 
		 int w = input.getWidth();
		 int h = input.getHeight();
 
 
		 boolean zoom = (w > getWidth() || h > getHeight());
		    if (zoom)
		    	{
		    	g.drawImage(input, 0, 0, getWidth(), getHeight(), null);
		    	}
		    else
		    	{
		    	g.drawImage(input, (getWidth()-w)/2, (getHeight()-h)/2, null);
		    	}
 
	g.dispose();	 
	}	
}
++