Is it possible to make this more consise by combinding if-statements with && or something else? I've tried a lot and I cant seem to make it work. If I could get any example on one or two rows of the code I would be very thankful.
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == button[0])
display.append("7");
if (ae.getSource() == button[1])
display.append("8");
if (ae.getSource() == button[2])
display.append("9");
if (ae.getSource() == button[3]) {
temporary[0] = Double.parseDouble(display.getText());
function[0] = true;
display.setText("");
}
if (ae.getSource() == button[4])
display.append("4");
if (ae.getSource() == button[5])
display.append("5");
if (ae.getSource() == button[6])
display.append("6");
if (ae.getSource() == button[7]) {
temporary[0] = Double.parseDouble(display.getText());
function[1] = true;
display.setText("");
}
if (ae.getSource() == button[8])
display.append("1");
if (ae.getSource() == button[9])
display.append("2");
if (ae.getSource() == button[10])
display.append("3");
if (ae.getSource() == button[11]) {
temporary[0] = Double.parseDouble(display.getText());
function[2] = true;
display.setText("");
}
if (ae.getSource() == button[12])
display.append(".");
if (ae.getSource() == button[13]) {
temporary[0] = Double.parseDouble(display.getText());
function[3] = true;
display.setText("");
}
if (ae.getSource() == button[14])
clear();
if (ae.getSource() == button[15])
getSqrt();
if (ae.getSource() == button[16])
getPosNeg();
if (ae.getSource() == button[17])
getResult();
if (ae.getSource() == button[18])
display.append("0");
}
Aucun commentaire:
Enregistrer un commentaire