Bonjour,
Je suis occupé à faire ma petite interface graphique pour dessiner
J'ai la classe ci-dessous qui fonctionne et j'ai créé 4 autres classe (A/B/C/B)
j'appelle donc une des ces classes en cliquant sur le bouton b1 ou b2...et donc le constructeur de la classe est appelée. J'ai juste la classe A ci-dessous pour exemple.
Comment faire pour que les instructions que je vais mettre dans paintComponent soient exécutées en cliquant sur le bouton??


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
import java.awt.Color;
import java.awt.Graphics;
 
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
 
 
public class A extends JFrame {
 
 
	private JPanel p11;
 
	public A()
	{
 
		setLayout(null);
		setSize(800,500);
		setResizable(false);
		setLocationRelativeTo(null);	
		setVisible(true);
 
		p11=new JPanel();
		p11.setBounds(0,0,800,500);
		p11.setBackground(new Color(220,250,204));
		add(p11);
	}
 
 
       public void paintComponent(Graphics g)
        {
 
 
        }
 
 
	 }

--------------------------------------------------

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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
 
import javax.swing.AbstractButton;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
 
import com.sun.xml.internal.ws.api.server.Container;
 
 
 
public class ExFlowLayout extends JFrame implements ActionListener {
 
private JLabel label1;
private JLabel label2;
private JLabel label3;
private JButton b1;
private JButton b2;
private JButton b3;
private JButton b4;
 
private JPanel p;
private ImageIcon image1;
private ImageIcon image2;
 
 
	public ExFlowLayout()
	  {
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-YYYY  HH-mm-ss");
		dateFormat.format(new Date());
 
 
		this.setTitle("Interface Graphique Fractals");
 
		setLayout(null);
		setSize(600,400);
		setResizable(false);
 
		b1=new JButton("FRACTAL 1");
		b1.setSize(100,20);
		b1.setLocation(238,100);
	//	b1.setBackground(Color.gray);
		b1.setForeground(Color.BLUE);
		b1.addActionListener(this);
		add(b1);
 
 
		b2=new JButton("FRACTAL 2");		
		b2.setSize(100,20);
		b2.setLocation(238,150);
		b2.setForeground(Color.blue);
		b2.addActionListener(this);
		add(b2);
 
		b3=new JButton("FRACTAL 3");		
		b3.setSize(100,20);
		b3.setLocation(238,200);
		b3.setForeground(Color.blue);
		b3.addActionListener(this);
		add(b3);
 
		b4=new JButton("FRACTAL 3");		
		b4.setSize(100,20);
		b4.setLocation(238,250);
		b4.setForeground(Color.blue);
		b4.addActionListener(this);
		add(b4);
 
 
 
 
 
		image1=new ImageIcon(getClass().getResource("index.jpg"));
		label1=new JLabel(image1);
		label1.setSize(125,125);
		label1.setLocation(0,100);
		add(label1);
 
		image2=new ImageIcon(getClass().getResource("index1.jpg"));
		label2=new JLabel(image2);
		label2.setSize(125,125);
		label2.setLocation(470,100);
		add(label2);
 
 
		JLabel label3=new JLabel("              Simulation sur les fractals");
		label3.setLocation(0,0);
		label3.setSize(600,20);
		label3.setBackground(Color.orange);
		label3.setBorder(null);	
		add(label3);
 
 
		p=new JPanel();	
		p.setBounds(0,0,600,400);
		p.setBackground(new Color(255,250,204));				
		add(p);
 
 
 
	 }
 
	public void actionPerformed(ActionEvent ev)
	  {
		 Object  source=ev.getSource();	
 
		if(source.equals(b1))		
		    new A();		
 
		else			
	    if(source.equals(b2))
	    	new B();	
 
	    else			
		    if(source.equals(b3))
		    	new C();
 
		    else			
			    if(source.equals(b4))
			    	new D();
	  }
 
 
	public static void main(String[] args)
	 {
 
		 try {
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	    ExFlowLayout f=new ExFlowLayout();
	    f.setLocationRelativeTo(null);
	    f.setVisible(true);
 
	 }
 
}