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 9241825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:26:53+00:00 2026-06-18T08:26:53+00:00

In a previous question, it was recommended I used the following format to assign

  • 0

In a previous question, it was recommended I used the following format to assign specific methods to specific Jbuttons. I get the same errors for each button.

public class MealPlannerGUI 
{
    JPanel foodOptions;
    JButton pButton;
    JButton cButton;
    JButton fButton;
    static JComboBox[] box= new JComboBox[3];

    JPanel search;
    JLabel searchL ;
    JTextField foodSearch;
    JButton startSearch;

    JPanel foodProfile;
    JLabel foodLabel;
    JTextArea foodInfo;
    JButton addFood;

    JPanel currentStatus;
    JLabel foodsEaten;
    JComboBox foodsToday;
    JLabel calories;
    JTextArea totalKCal;
    JButton clearInfo;
     //ow Carbs
    FoodListMaker tester = new FoodListMaker();
    public void go()
    {
        JFrame frame = new JFrame();

        foodOptions = new JPanel();
        foodOptions.setBackground(Color.darkGray);

        pButton = new JButton ("Add");
        cButton = new JButton ("Add");
        fButton = new JButton ("Add");

        for (int i = 0; i<3; i++)
        {

            box[0] = new JComboBox (tester.groupProtein());
            box[1] = new JComboBox (tester.groupKCal());
            box[2] = new JComboBox (tester.groupFat());

            //box[3]= new JComboBox (fillOptionPanel(carbFoods.groupCarb())); 
            foodOptions.add(box[i]);
        }

        search = new JPanel();
        search.setBackground(Color.BLUE);
        search.setLayout(new BoxLayout( search, BoxLayout.Y_AXIS));
        searchL = new JLabel("Search for a food:");
        //searchInfo= new JTextArea(10,20);
        startSearch = new JButton ("Search");
        //JScrollPane scrollPane = new JScrollPane(searchInfo); 
        foodSearch = new JTextField(10);
        search.add(searchL);
        search.add(foodSearch);
        //search.add(searchInfo);
        search.add(startSearch);


    foodProfile = new JPanel();
    foodLabel = new JLabel("Food Contents Profile:");
    foodInfo = new JTextArea(10,20);;
    addFood= new JButton ("Add");
    foodsEaten= new JLabel ("Foods consumed today:");
    foodsToday= new JComboBox();
    calories= new JLabel ("Calorie Counter");
    totalKCal = new JTextArea( 1 , 2);
    foodProfile.add( foodLabel);
    foodProfile.add( foodInfo);
    foodProfile.add( addFood);

    currentStatus = new JPanel();
    currentStatus.setLayout(new BoxLayout( currentStatus, BoxLayout.Y_AXIS));
    currentStatus.add( foodsEaten);
    currentStatus.add( foodsToday);
    currentStatus.add( calories);
    currentStatus.add( totalKCal);




        frame.getContentPane().add(BorderLayout.NORTH,foodOptions);
        frame.getContentPane().add(BorderLayout.WEST,search);
        frame.getContentPane().add(BorderLayout.CENTER,foodProfile);
        frame.getContentPane().add(BorderLayout.EAST,currentStatus);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(500,800);
        frame.setVisible(true);


    }
    startSearch.addActionListener(new ActionListener() 
    {               
        //@Override
        public void actionPerformed(ActionEvent e) 
        {       
            String str = foodSearch.getText();
            searchFoods(str, tester.getFoodList());
        }
    });


    addFood.addActionListener(new ActionListener() 
    {
         //@Override
         public void actionPerformed(ActionEvent e)
         {
            foodsEaten = add(currentFood);
            foodsToday = new JComboBox (foodsConsumed());
            calorieTracker(currentFood.getKCal());
        }
     });


    pButton.addActionListener(new ActionListener() 
    {
        //@Override
        public void actionPerformed(ActionEvent e)
        {
            String foodChoice = (String)box[0].getSelectedItem(); 
            searchFoods(foodChoice, tester.getFoodList());
        }
    });
    cButton.addActionListener(new ActionListener() 
    {
        //@Override
        public void actionPerformed(ActionEvent e)
        {
            String foodChoice = (String)box[1].getSelectedItem(); 
            searchFoods(foodChoice, tester.getFoodList());
        }
    });
    fButton.addActionListener(new ActionListener() 
    {
        //@Override
        public void actionPerformed(ActionEvent e)
        {
            String foodChoice = (String)box[2].getSelectedItem(); 
            searchFoods(foodChoice, tester.getFoodList());
        }
    });

The first error is about how @Override requires a “;” which shouldn’t be occuring.
The remaining errors refer to the structure of the code above :

mealplans/MealPlannerGUI.java:104: <identifier> expected
    startSearch.addActionListener(new ActionListener() 
                                 ^
mealplans/MealPlannerGUI.java:104: illegal start of type
    startSearch.addActionListener(new ActionListener() 
                                  ^
mealplans/MealPlannerGUI.java:104: ')' expected
    startSearch.addActionListener(new ActionListener() 
                                     ^
mealplans/MealPlannerGUI.java:104: ';' expected
    startSearch.addActionListener(new ActionListener() 
                                                    ^
mealplans/MealPlannerGUI.java:104: illegal start of type
    startSearch.addActionListener(new ActionListener() 
                                                     ^
mealplans/MealPlannerGUI.java:104: <identifier> expected
    startSearch.addActionListener(new ActionListener() 
  • 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-18T08:26:54+00:00Added an answer on June 18, 2026 at 8:26 am

    Non-declative statements can only appear in a constructor, method or static initializer rather than in the class block. You could move all calls to addActionListener into a initComponents method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On Previous Question , someone recommended that I install Andy's IDE Fix Pack to
Following up from my previous question. Can anyone explain why the following code compiles
In an answer to a previous question somebody recommended: have the SqlConnection a member
As recommended in a previous question of mine, I am using the PHP Simple
In a previous SO question it was recommended to me to use callback/event firing
My previous question on the same theme: C#: Asynchronous NamedPipeServerStream understanding Now I have
Previous question linky: MySQL Left Joins Very kindly we got the following code working:
In previous question of mine, someone had meantioned that using Semaphores were expensive in
This question is extended part of my previous question, Finding number position in string
This question is based on my previous question which I got a working answer

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.