Java can't find symbol, Java can't find my symbol in an array?

前端 未结 2 418
闹比i
闹比i 2021-01-29 16:32

This is the error i get when i write this line of code.

symbol  : variable isSeletecd
location: class java.lang.String
if (dorm[0].isSeletecd && meal[0].         


        
相关标签:
2条回答
  • 2021-01-29 17:15

    dorm and meal are String arrays, there is no isSeletecd field or isSelected() method on a java.lang.String.

    0 讨论(0)
  • 2021-01-29 17:28

    dorm and meal are String arrays

    There is no isSelected() method for the String class, but there is a getSelectedIndex() method for JComboBox which can be used to get the index no of the currently selected item in the JComboBox component.

    By replacing the condition in the if statement in your ButtonListener class

    from

    if (dorm[0].isSeletecd && meal[0].isSeletecd())
    

    to

    if(dormBox.getSelectedIndex()==0 && mealBox.getSelectedIndex()==0)
    

    will solve your problem.

    So your ButtonListener class will now be

    private class ButtonListener implements ActionListener { 
        public void actionPerformed(ActionEvent e) { 
            if(dormBox.getSelectedIndex()==0 && mealBox.getSelectedIndex()==0)
                totalCharges.setText("2150.00");
        } 
    } 
    

    Reffer getSelectedIndex() for more information.

    0 讨论(0)
提交回复
热议问题