lundi 8 juin 2015

if else statements with jTextField, wanting it to recoginize want to do if == 1 if else == 2, 3, 4

i have more but im wondering if there is a simplier way to do this? so if the user enters 1 it will to inches to cm if they enter 2 it will do cm to feet...etc

    if (jTextField1.getText() == 1) {
        InchesToCm();
} else if (jTextField1.getText() == 2) {
    CmToFeet();

} else if (jTextField1.getText() == 3) {
    MetresToYards();
}
else if (jTextField1.getText() == 4) {
    KmToMetres();
}
else { jLabel8.setText("Error, try again");

}

Aucun commentaire:

Enregistrer un commentaire