Réponse acceptée !
Salut,
pour reprendre le code avec l'astuce de
DARKSIDIOUSimport java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Test extends JFrame{
public Test(){
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(300, 700);
setLocationRelativeTo(null);
JPanel p = new JPanel();
JButton [] caractPdt = new JButton[20];
for(int i = 0; i < caractPdt.length; i++){
caractPdt[i]= new JButton ("Voir le produit commander "+i);
caractPdt[i].setName("" + i);
caractPdt[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JButton b = (JButton)e.getSource();
System.out.println("B entré "+b.getName());
}
});
p.add(caractPdt[i]);
}
setContentPane(p);
}
public static void main(String[] args) {
new Test().setVisible(true);
}
}
------------------------------------
"On n'est pas au resto : ici on ne fait pas dans les plats tout cuits ..."
WORA