I'm using the JCreator to design a JFrame that's supposed to calculate Daily Calories Intake and I need to check two conditions JComboBox (male/female) and whether the calculate button is clicked or not.
I think it's easier if I show the actionperformed method - here it is:
public void actionPerformed(ActionEvent ae)
{
String s1 = ae.getActionCommand();
String s2 = (String)gender.getSelectedItem();
double a=Double.parseDouble(t1.getText());
double w=Double.parseDouble(t2.getText());
double h=Double.parseDouble(t3.getText());
if(s2.equals("Female"))
{ calo=fCalo(w,h,a);}
else if(s2.equals("Male"))
{ calo=mCalo(w,h,a);}
if(s1.equals("Calculate"))
{
t4.setText(String.valueOf(calo+650));
t5.setText(String.valueOf(calo));
t6.setText(String.valueOf(calo-500));
}
}
I tried also doing this:
if(s1.equals("Calculate"))
{
if(s2.equals("Female"))
{ calo=fCalo(w,h,a);}
else if(s2.equals("Male"))
{ calo=mCalo(w,h,a);}
t4.setText(String.valueOf(calo+650));
t5.setText(String.valueOf(calo));
t6.setText(String.valueOf(calo-500));
}
}
But it keep giving me error message whenever I choose male or female and nothing happens. I mean results is not showing. I literally tried everything. The second part of my program have similar code to this and it do check the two conditions then show results perfectly.
Aucun commentaire:
Enregistrer un commentaire