Help with simple calculation
I'm slowly learning myself Java through JBuilder 6. I'm currently on with a currency convertor, one of my first programs that does more than say "Hello world". Anyway, this is a section of my code
void submit_actionPerformed(ActionEvent e) {
String s = jTextField1.getText();
try {
val = Double.parseDouble(s);
}
catch (NumberFormatException exp) {
val = 0;
}
if (jComboBox2.getSelectedItem() == "US Dollar") {
dResult = val * dDollar;
}
else if (jComboBox2.getSelectedItem() == "Pound Sterling") {
dResult = val * dPound;
}
else if (jComboBox2.getSelectedItem() == "Euro") {
dResult = val * dEuro;
}
else if (jComboBox2.getSelectedItem() == "Bahrain Dinar") {
dResult = val * dDinar;
}
else if (jComboBox2.getSelectedItem() == "Australian Dollar") {
dResult = val * dADollar;
}
else
dResult = val *dYen;
jTextField2.setText("" + dResult);
}
void jButton1_actionPerformed(ActionEvent e) {
jTextField2.setText("" + dResult);
}
-
The idea is for the user to enter their amount, select which currency they want from the combobox, then the result is displayed back to them. However, each time I run this program as it is, the result is always zero. I assume there's something wrong in the calculation, can anyone help me?

