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
|
public void actionPerformed(ActionEvent e) {
if (e.getSource() == bouton0||e.getSource() == outon1||e.getSource() == bouton2||e.getSource() == bouton3
||e.getSource() == bouton4||e.getSource() == bouton5||e.getSource() == bouton6||e.getSource() == bouton7
||e.getSource() == bouton8||e.getSource() == bouton9){
champAffichage.setText(((JButton) e.getSource()).getLabel());
}
// champAffichage.setText(champAffichage.getText()+ ((JButton) e.getSource()).getLabel());
else if (e.getSource()==boutonOp){
res1=Double.parseDouble(champAffichage.getText());
champAffichage.setText(""+res1);
add=true;minus=false;
}
else if (e.getSource()==boutonSous){
res1=Double.parseDouble(champAffichage.getText());
champAffichage.setText(""+res1);
minus=true;add=false;
}
else if (e.getSource()==boutonEgale){
resultat();
}
}
void resultat() {
double res2 =Double.parseDouble(champAffichage.getText());
if (add){champAffichage.setText(""+(res1+res2)); }
else if (minus){champAffichage.setText(""+(res1-res2)); } |
Partager