Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: JCombobox Warnings

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.


        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\pk gCarInsuranceCalc\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\pk gCarInsuranceCalc\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\pk gCarInsuranceCalc\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
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: JCombobox Warnings

    Either your development environment changed to allow previously suppressed warnings, or the Java version changed so that code that didn't deserve a warning in Java 6 does in Java 7 where the JComboBox became a generic. If your program must compile successfully in both Java 6 (or earlier) and Java 7 environments, then ignore the warnings when in a Java 7 environment and leave JComboBox unparameterized. If you can be sure that you'll be compiling in Java 7 or later, then parameterize it. If you haven't yet learned generics (or don't want to), then the choice is made for you.

Similar Threads

  1. Help With JComboBox
    By Olympaphibian89 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 6th, 2012, 08:06 PM
  2. JComboBox
    By ikocijan in forum What's Wrong With My Code?
    Replies: 9
    Last Post: July 16th, 2012, 06:35 AM
  3. Replies: 3
    Last Post: March 6th, 2012, 03:50 AM
  4. JComboBox
    By SV25 in forum Java Theory & Questions
    Replies: 2
    Last Post: April 20th, 2011, 08:47 AM
  5. [SOLVED] JCombobox help
    By sman36 in forum AWT / Java Swing
    Replies: 10
    Last Post: August 11th, 2010, 04:11 AM

Tags for this Thread