Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7824797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:43:12+00:00 2026-06-02T08:43:12+00:00

I have a homework assignment where I am buildign a GUI JPane that holds

  • 0

I have a homework assignment where I am buildign a GUI JPane that holds other JPanes to allow for multiple objects to be displayed. I am getting a compile error on one of my listeners and could use some help figuring this one out. Let me preface all of this by saying that we are not allowed to use an IDE.

The error is:

F:\Java\Lab 8\Lab8.java:84: error: cannot find symbol
        jcbo.addListSelectionListener(new ListSelectionListener() {
            ^
  symbol:   method addListSelectionListener(<anonymous ListSelectionListener>)
  location: variable jcbo of type JComboBox<String>
1 error

The project code is:

import java.awt.*;
   import java.awt.event.*;
   import javax.swing.*;
   import javax.swing.event.*;
   import javax.swing.border.*;
   import java.util.Scanner;
   import java.util.EventObject;


   public class Lab8 extends JFrame {

       public String name;
       public String[] ageRanges = {"Select an Age Range","Under 20", "20-29", "30-39", "40-49", "50-59", "60 and Above"};
       public String[] destination = {"Mercury", "Venus", "Moon", "Mars", "Jupiter / Europa", "Saturn / Triton", "Pluto + Sharon"};
        final JTextField txtName = new JTextField(20);
        String value;


       public Lab8()
       {





           // Create an array of Strings for age ranges
           final JComboBox<String> jcbo = new JComboBox<String>(ageRanges);
           jcbo.setForeground(Color.blue);
           jcbo.setBackground(Color.white);


           // Create an array of String destinations




           // Declare radio buttons
           JRadioButton jrbMonday, jrbTuesday, jrbWednesday, jrbThursday, jrbFriday;

           // Create a textfield
           JTextField jMsg = new JTextField(10);


           // Create panel to hold label and textbox.
           JPanel p1 = new JPanel();
           p1.setLayout(new BorderLayout(5,0));
           p1.add(new JLabel("Name: "), BorderLayout.WEST);

           p1.add(txtName, BorderLayout.CENTER);
           jMsg.setHorizontalAlignment(JTextField.LEFT);


           // Create combobox panel.
           JPanel p2 = new JPanel();
           p2.setLayout(new GridLayout(2,0,5,5));
           p2.add(p1, BorderLayout.NORTH);
           p2.add(new JComboBox<String>(ageRanges), BorderLayout.CENTER);
           p2.setBorder(new TitledBorder("Passenger Name & Age Range"));

            final JList<String> jlst = new JList<String>(destination);

           //Create listbox panel.
           JPanel p3 = new JPanel();
           p3.setLayout(new GridLayout(1, 0));
           p3.add(jlst);
           p3.setBorder(new TitledBorder("Destinations"));



            jlst.addListSelectionListener(new ListSelectionListener() {

                public void valueChanged(ListSelectionEvent e){

                    final int index = jlst.getSelectedIndex();
                    value = destination[index];
                }
            });


            jcbo.addListSelectionListener(new ListSelectionListener() {

                public void valueChanged(ListSelectionEvent e){

                    final int index = jcbo.getSelectedIndex();
                    value = ageRanges[index];
                }
            });




           // Create a print button
           JButton jbtPrint = new JButton("Print");


           // Create a new panel to hold radio buttons.
           JPanel r1 = new JPanel();
           r1.setLayout(new GridLayout(3,2));
           r1.add(jrbMonday = new JRadioButton("Monday"));
           r1.add(jrbTuesday = new JRadioButton("Tuesday"));
           r1.add(jrbWednesday = new JRadioButton("Wednesday"));
           r1.add(jrbThursday = new JRadioButton("Thursday"));
           r1.add(jrbFriday = new JRadioButton("Friday"));
           r1.setBorder(new TitledBorder("Departure Days"));
           r1.add(jbtPrint);


           // Create a radio button group to group five buttons
           ButtonGroup group = new ButtonGroup();
           group.add(jrbMonday);
           group.add(jrbTuesday);
           group.add(jrbWednesday);
           group.add(jrbThursday);
           group.add(jrbFriday);



           // Create grid to hold contents
           JPanel pMain = new JPanel();
           pMain.setLayout(new BorderLayout(5,0));
           add(r1, BorderLayout.CENTER);
           add(p2, BorderLayout.NORTH);
           add(p3, BorderLayout. EAST);



           // Create button listener
           jbtPrint.addActionListener(new ButtonListener());

            jrbMonday.addActionListener(new mListener());
            jrbTuesday.addActionListener(new tListener());
            jrbWednesday.addActionListener(new wListener());
            jrbThursday.addActionListener(new rListener());
            jrbFriday.addActionListener(new fListener());



}
            int flag = 0;


            // Declare radio button variable
            boolean monday, tuesday, wednesday, thursday, friday;

            public void monday(){
                monday = true;
            }
            public void tuesday(){
                tuesday = true;
            }
            public void wednesday(){
                wednesday = true;
            }
            public void thursday(){
                thursday = true;
            }
            public void friday(){
                friday = true;
            }





            public class mListener implements ActionListener
            {
              public void actionPerformed(ActionEvent e)
              {
              monday();
                flag = 1;
              }
            }

            public class tListener implements ActionListener
                        {
              public void actionPerformed(ActionEvent e)
              {
              tuesday();
                flag = 2;
              }
            }

            public class wListener implements ActionListener
            {
              public void actionPerformed(ActionEvent e)
              {
              wednesday();
                flag = 3;
              }
            }

            public class rListener implements ActionListener
            {
              public void actionPerformed(ActionEvent e)
              {
              thursday();
                flag = 4;
              }
            }

            public class fListener implements ActionListener
            {
              public void actionPerformed(ActionEvent e)
              {
              friday();
              flag = 5;
              }
            }

            public void setText(){
                name = txtName.getText();
        }


           /** Handle the print button */
             class ButtonListener implements ActionListener {
                 ButtonListener(){
                 }
               public void actionPerformed(ActionEvent e) {
                 // Get values from fields
                    setText();
                System.out.println("Passenger's Name: " + name + "\n");
                System.out.println("Age Group: " + ageRanges + "\n");
                System.out.println("Destination: " + value + "\n");
                System.out.println("Departure Day: " + flag  + "\n");



                }
                /*jbtPrint.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e)
                    {

                    }
                });*/

}





public static void main(String[] args)
       {
           Lab8 frame = new Lab8();
           // frame.pack();
           frame.setTitle("Lab 8 Application");
           frame.setLocationRelativeTo(null); // Center the frame
           frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           frame.setSize(425, 275);
           frame.setVisible(true);


        }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:43:13+00:00Added an answer on June 2, 2026 at 8:43 am

    JComboBox simply has no method addListSelectionListener(...). It’s not a list after all.

    From your code, it looks like you want some code to trigger when the user selects something in your JComboBox. Use an ActionListener for that:

    jcbo.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        int index = jcbo.getSelectedIndex();
        value = ageRanges[index];
      }
    });
    

    Completely unrelated to the previous:

    For the [Ljava.lang.String;@1283052, note that calling toString() on an array (or concatenating it to an existing string which has the same effect), doesn’t give you the contents but a mix of the array type and some internal hash code. For the contents use one of the Arrays.toString() methods:

    System.out.println("Age Group: " + Arrays.toString(ageRanges) + "\n");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a homework assignment that deals with classes and objects. In it,
For my homework assignment, I have a network of Nodes that are passing messages
I have a homework assignment in Java that is tested using the commands: make
I have a homework assignment that I am supposed to write a http server
I have a homework assignment, and i am finished other then one question (see
Im almost done with a homework assignment that multiplies polynomials and has to have
I have a homework assignment that asks to create an order form. The order
I'm very new to XML and XSLT. I have a homework assignment that asks
I have a homework assignment where I need to take input from a file
I have a homework assignment to sort an array in ascending order. Obviously, this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.