En essayant de faire un simple ActionEvent j'ai rencontré ce problème "button cannot be resolved to a variable"
le morceau du codé affecté est le suivant
Code : Sélectionner tout - Visualiser dans une fenêtre à part
 if(e.getSource() == bouton2)
le code complet est le suivant:
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
 import java.awt.EventQueue;
 
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JFileChooser;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.LayoutStyle.ComponentPlacement;
 
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
 
 
public class tpjava extends JFrame implements ActionListener{
 
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
    JButton  bouton1;
	JTextArea textArea1=null;
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					tpjava frame = new tpjava();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
 
 
	/**
         * Create the frame.
         */
	public tpjava() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 660, 478);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
 
 
 
		JFileChooser fileChooser = new JFileChooser();
 
		JButton bouton1 = new JButton("Acheter");
		bouton1.addActionListener(this);
 
		JButton bouton2 = new JButton("Afficher");
		bouton2.addActionListener(this);
 
		JButton bouton3 = new JButton("Sauvegarder");
		bouton3.addActionListener(this);
 
		JButton bouton4 = new JButton("Fichier1");
		bouton4.addActionListener(this);
 
		JButton bouton5 = new JButton("Fichier2");
		bouton5.addActionListener(this);
 
		JButton bouton6 = new JButton("Fichier3");
		bouton6.addActionListener(this);
 
		JTextArea textArea1 = new JTextArea();
 
 
		JTextArea textArea2 = new JTextArea();
 
 
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(fileChooser, GroupLayout.PREFERRED_SIZE, 494, GroupLayout.PREFERRED_SIZE)
							.addGap(18)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addComponent(bouton4, GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
								.addComponent(bouton5, GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
								.addComponent(bouton6, GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addContainerGap()
							.addComponent(textArea1, GroupLayout.PREFERRED_SIZE, 248, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addComponent(bouton3, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
								.addComponent(bouton2, GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
								.addComponent(bouton1, GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(textArea2, GroupLayout.DEFAULT_SIZE, 255, Short.MAX_VALUE)))
					.addContainerGap())
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
							.addContainerGap()
							.addComponent(bouton1)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(bouton2)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(bouton3))
						.addComponent(textArea1, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
						.addComponent(textArea2, GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE))
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(20)
							.addComponent(fileChooser, GroupLayout.PREFERRED_SIZE, 238, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(56)
							.addComponent(bouton4)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(bouton5)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(bouton6))))
		);
		contentPane.setLayout(gl_contentPane);
	}
 
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == bouton2) {
		Personnevoiture frame = new Personnevoiture();
		frame.setVisible(true);
		}		
	}
}
le problème qu'il ne trouve pas la variable bouton2