Bonjour j'ai un petit blem , en fait je voulais afficher un rectangle (qui se trouve dans un autre classe ) si j'appui sur le bouton rectangle sa doit afficher le rectangle avec les parametres passés dans la methode rect , mais jusqua present rien du tout . Je veux votre aide SVP !!!!
classe appelant le dessin AppPaint :
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 class Graphic : import java.awt.Color; import java.awt.Component; import java.awt.Graphics; public class Graphic extends Component{ int u=0,x=0,y=0,z=0; int u1=0,x2=0,y3=0,z4=0; Color couleur = Color.black; Color couleur1 = Color.black; public void paint(Graphics g) { g.setColor(couleur); g.drawRect(u, x, y,z); g.setColor(couleur1); g.drawOval(u1, x2, y3,z4); } public void rect(int u, int x, int y, int z,Color couleur1) { this.u=u; this.x=x; this.y=y; this.z=z; this.couleur1= couleur1; repaint(); } public void cer(int u1, int x2, int y3, int z4,Color couleur) { this.u1=u1; this.x2=x2; this.y3=y3; this.z4=z4; this.couleur= couleur; repaint(); } }
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 import java.awt.Color; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class AppPaint extends JFrame { public AppPaint() { Graphic cg = new Graphic(); JPanel Panel = new JPanel(); JButton bouton; JButton bouton1; bouton1 = new JButton("rectangle"); bouton = new JButton("cercle"); this.add(Panel); Panel.add(bouton1); Panel.add(bouton); Panel.add(cg); bouton1.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent arg0) { cg.rect(100, 100, 100, 100, Color.GREEN); } }); this.setSize(400,400); this.setTitle("Application de paint"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } public static void main (String arg[]) { new AppPaint(); } }
Partager