#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    37
    Rep Power
    2

    JCombobox Warnings


    When I was compiling and running my program yesterday I wasn't receiving any warnings then when I compile and run it today I'm now receiving warnings, can someone help me solve this problem, I have pasted the code and warnings.

    Code:
        public CarInsuranceCalc()
            { // CarInsuranceCalc method
            super("Car Insurance Price Index Calculator");
                    
                    // setting layout
            setLayout(new FlowLayout());
                    
                    // label for gender
                    lblGender = new JLabel("Gender:");
                    add(lblGender);
                    
                    // combobox for gender
            cboGender = new JComboBox(Gender);
                    cboGender.setSelectedItem(null); // sets default value
            cboGender.addItemListener(
                new ItemListener()
                            {
                    public void itemStateChanged(ItemEvent event)
                                    {
                                        // sets combobox value equals selected value
                                        if(event.getStateChange()==ItemEvent.SELECTED)
                                        {
                                            // sets variable value to selected value
                                            strGender = String.valueOf(cboGender.getSelectedItem());
                                            if(strGender=="Male" && strAge!=null)
                                            {
                                                dblRate = MaleRate[cboAge.getSelectedIndex()];
                                            }
                                            if(strGender=="Female" && strAge!=null)
                                            {
                                                dblRate = FemaleRate[cboAge.getSelectedIndex()];
                                            }
                                        }
                                    } // end of event handler
                }
            ); // end of listener
            add(cboGender);    
                    
                    // label for age
                    lblAge = new JLabel("   Age:");
                    add(lblAge);
                    
                    // combobox for age
             cboAge = new JComboBox(Age);
                    cboAge.setSelectedItem(null); // sets default value
            cboAge.addItemListener(
                new ItemListener()
                            {
                    public void itemStateChanged(ItemEvent event)
                                    {
                                        // sets combobox value equals selected value
                                        if(event.getStateChange()==ItemEvent.SELECTED)
                                        {
                                            // sets variable value to selected value
                                            strAge = String.valueOf(cboAge.getSelectedItem());
                                            if(strGender=="Male")
                                            {
                                                dblRate = MaleRate[cboAge.getSelectedIndex()];
                                            }
                                            if(strGender=="Female")
                                            {
                                                dblRate = FemaleRate[cboAge.getSelectedIndex()];
                                            }
                                        }
                                    } // end of event handler
                }
            ); // end of listener
            add(cboAge);
                    
                    // label for no claims
                    lblNoClaim = new JLabel("   No Claims:");
                    add(lblNoClaim);
                    
                    // combobox for no claims
             cboNoClaim = new JComboBox(NoClaim);
                    cboNoClaim.setSelectedItem(null); // sets default value
            cboNoClaim.addItemListener(
                new ItemListener()
                            {
                    public void itemStateChanged(ItemEvent event)
                                    {
                                        // sets combobox value equals selected value
                                        if(event.getStateChange()==ItemEvent.SELECTED);
                                        {
                                            // sets variable value to selected value
                                            strNoClaim = String.valueOf(cboNoClaim.getSelectedItem());
                                            dblNoClaimDiscount = NoClaimDiscount[cboNoClaim.getSelectedIndex()];
                                        }
                                    } // end of event handler
                }
            ); // end of listener
            add(cboNoClaim);
                    
                    btnCalculate = new JButton("Calculate");
                    add(btnCalculate);
                    HandlerClass handler = new HandlerClass();
                    btnCalculate.addActionListener(handler);
                    
        } // end of CarInsuranceCalc method
    C:\Users\Admin\Desktop\projCarInsuranceCalc\src\pkgCarInsuranceCalc\CarInsuranceCalc.java:50: warning: [unchecked] unchecked call to JComboBox(E[]) as a member of the raw type JComboBox
    cboGender = new JComboBox(Gender);
    ^
    where E is a type-variable:
    E extends Object declared in class JComboBox
    C:\Users\Admin\Desktop\projCarInsuranceCalc\src\pkgCarInsuranceCalc\CarInsuranceCalc.java:81: warning: [unchecked] unchecked call to JComboBox(E[]) as a member of the raw type JComboBox
    cboAge = new JComboBox(Age);
    ^
    where E is a type-variable:
    E extends Object declared in class JComboBox
    C:\Users\Admin\Desktop\projCarInsuranceCalc\src\pkgCarInsuranceCalc\CarInsuranceCalc.java:112: warning: [unchecked] unchecked call to JComboBox(E[]) as a member of the raw type JComboBox
    cboNoClaim = new JComboBox(NoClaim);
    ^
    where E is a type-variable:
    E extends Object declared in class JComboBox
    3 warnings
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    103
    Rep Power
    3
    I can't say for sure without trying the fix, but the warnings sound like they are appearing because you aren't using Generics.

    Try explicitly saying what kind of object your JComboBox will contain by declaring and initializing them as JComboBox<ObjectType>.

    Comments on this post

    • 0w1 agrees : Thank you

IMN logo majestic logo threadwatch logo seochat tools logo