0

Action performed here and the month is always executed with the else condition.

public void actionPerformed(ActionEvent e) {
    tmonthin.setText((((JComboBox) e.getSource()).getSelectedItem()
            .toString()) + "   ");
    Month = tmonthin.getText();
    System.out.println(Month);
    System.out.println("aby");
    int n;
    System.out.println(Month);
    if (Month.equals("March") || "January".equals(Month)
            || "May".equals(Month) || Month == "July" || Month == "August"
            || Month == "October" || Month == "December") {
        System.out.println("abd");
        n = 31;
    } else if (Month == "February") {
        n = 28;
    } else {
        System.out.println("bnbn");
        n = 30;
    }
}
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • `"February".equals(Month)` – Manos Nikolaidis Nov 02 '15 at 12:21
  • Why exactly are you using 3 different types of string comparison (one of which `==` is incorrect)? – Arc676 Nov 02 '15 at 12:21
  • Please use equals() for exact string comparison or equalsIgnoreCase() if it is not case sensitive exact string comparison – a3.14_Infinity Nov 02 '15 at 12:24
  • Month.equals("February") and Month == "February" are not the same in Java. The first one is a content based equality and returns true. The second one is reference based equality, which would return false. – Pavan Dittakavi Nov 02 '15 at 12:24
  • What is the dataType of Month?? I think you should use tmonthin.getText().toString() while getting the value of that text. – Shivam Nov 02 '15 at 12:25

0 Answers0