1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| // Boucle de création des boutons Delta, Graph, +, -, *, %, C, ON,x^, ,...
final JButton[] tabButton = new JButton[12] ;
String[] tabButtonLabels = {"C", ",", "%", "Graph", "Delta", "+", "-"
, "/", "*", "x^", "ON", "="};
for (int j=0 ; j<tabButton.length ; j++)
tabButton[j] = new JButton(tabButtonLabels[j]) ;
// Boucle de création des boutons "chiffre"
final JButton [] caractPdt = new JButton[10]; // On veut 10 boutons
for(int i = 0; i < caractPdt.length; i++){
caractPdt[i]= new JButton (""+i);
caractPdt[i].setName("bouton" + i);
// on place apres chaque bouton son chiffre (i)
// incrémenté
caractPdt[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JButton b = (JButton)e.getSource();
System.out.println("bouton "+b.getName());
}
});
panel.add(caractPdt[i]);
}
setContentPane(panel); |
Partager