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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:25:15+00:00 2026-05-28T04:25:15+00:00

I have written code to perform click event on JMenuItem but that is not

  • 0

I have written code to perform click event on JMenuItem but that is not firing when I am debugging. (I know that I am not supposed to ask these questions in this forum but I am new to this forum)

public class ClsMenu extends JMenuItem implements ActionListener {

  JTextArea output;
  JScrollPane scrollPane;

  public ClsMenu(String text)
  {
    super(text);
    addActionListener(this);
  }

  public JMenuBar createMenu()
  {
    JMenuBar menuBar;
    JMenu menuFood,menuDrinks,menuParty;
    JMenuItem foodItem;


    menuBar=new JMenuBar();


    menuFood=new JMenu("Food");
    foodItem=new JMenuItem("Pizza");
    menuFood.add(foodItem);
    menuBar.add(menuFood);
    return menuBar;
  }
  public void createGUIandShow()
  {
    JFrame frame = new JFrame("Restuarant");
    frame.setJMenuBar(createMenu());
  }

  public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    System.out.println("item clicked"+e.getActionCommand());
  }
}

In this call, I have created an object

public class ClsMenuDisp {
  public static void main(String[] args) {
    // TODO Auto-generated method stub

    ClsMenu menu=new ClsMenu("testitem");
    menu.createGUIandShow();
  }
}
  • 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-05-28T04:25:15+00:00Added an answer on May 28, 2026 at 4:25 am

    You need to add your ActionListener to the menu items you are adding the the JMenu. What you are doing is make a menu item that has a action listener. Then using a instance method of that menu item to create a completely unrelated JMenuBar/JMenu/JMenuItem that is then attached to the JFrame.

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

Sidebar

Related Questions

I have written the following code which will does not work but the second
I have written a small piece of code that would perform Run length encoding
I have written code that automatically creates CSS sprites based on the IMG tags
I have written code that opens 16 figures at once. Currently, they all open
I have written some code to ensure that items on an order are all
In jQuery, I have written a piece of code that appears on every page
I have written the following code to perform some simultaneous HTTP posting and file
I have written a Magento module to listen for the OrderSave event and perform
A lot of the code base methods my peers have written perform their own
I have written code in Java to access web cam,and to save image... I

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.