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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:08:14+00:00 2026-06-14T13:08:14+00:00

as the title states, i need to know how to determine if a menu

  • 0

as the title states, i need to know how to determine if a menu item was clicked or not, then run the function associated. for instance i have a JMenu with a JMenuItem “exit”, which when clicked should run a close form method.

import javax.swing.*;

public class selector_form extends JFrame {


/**
 * 
 */
private static final long serialVersionUID = -5963842156289770842L;

public selector_form(String name)
{
    super.setTitle(name);
    setupComponents(this);
    super.setVisible(true);

}

private void setupComponents(JFrame frame)
{

    JMenuItem file_items = new JMenuItem("Exit");
    JMenuItem config_items = new JMenuItem("Preferences");
    JMenuItem[] machine_items = {new JMenuItem("Refresh"), 
            new JMenuItem("Add Dynamically"), new JMenuItem("Remove Dynamically")
    };
    JMenuItem[] emulator_items = {new JMenuItem("Start Emulator"),
            new JMenuItem("Stop Emulator"), new JMenuItem("Pause Emulator"),
            new JMenuItem("Reset Emulator"), new JMenuItem("Crash Emulator")
    };
    JMenuItem[] memory_items = {new JMenuItem("View Emulator Memory"),
            new JMenuItem("System Cheats"), new JMenuItem("Dump Emulator Memory"),
            new JMenuItem("Edit Specific Address"), 
            new JMenuItem("Show Allocations"), new JMenuItem("Allocate Memory"),
            new JMenuItem("DeAllocate Memory")
    };
    JMenuItem[] cpu_items = {new JMenuItem("Show Host Specs"),
            new JMenuItem("Show Emulator Specs"), 
            new JMenuItem("Enable HyperThreadding")
    };
    JMenuItem[] about_items = {new JMenuItem("Help Contents"), 
            new JMenuItem("About")
    };

    frame.setSize(800, 600);

    JMenuBar jmb = new JMenuBar();
    JMenu jm_a = new JMenu("File");
    JMenu jm_c = new JMenu("Config");
    JMenu jm_d = new JMenu("Machines");
    JMenu jm_e = new JMenu("Emulator");
    JMenu jm_f = new JMenu("Memory");
    JMenu jm_g = new JMenu("CPU");
    JMenu jm_h = new JMenu("About");

    jm_a.add(file_items);
    jm_c.add(config_items);
    for(JMenuItem item : machine_items)
        jm_d.add(item);
    for(JMenuItem item : emulator_items)
        jm_e.add(item);
    for(JMenuItem item : memory_items)
        jm_f.add(item);
    for(JMenuItem item : cpu_items)
        jm_g.add(item);
    for(JMenuItem item : about_items)
        jm_h.add(item);

    jmb.add(jm_a);
    jmb.add(jm_c);
    jmb.add(jm_d);
    jmb.add(jm_e);
    jmb.add(jm_f);
    jmb.add(jm_g);
    jmb.add(jm_h);
    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);

    frame.setJMenuBar(jmb);

}

}
  • 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-14T13:08:16+00:00Added an answer on June 14, 2026 at 1:08 pm

    You can do this with an ActionListener. You can create your own ActionListener class.

    class MenuActionListener implements ActionListener {
      public void actionPerformed(ActionEvent e) {
        System.out.println("Selected: " + e.getActionCommand());    
      }
    }
    

    Than add it to the JMenuItem.

    JMenuItem newMenuItem = new JMenuItem("New");
    newMenuItem.addActionListener(new MenuActionListener());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As title states, if I have a float, I need to get the fraction
As the title states really, I need to know if a 32bit application can
As the title states, I need to relace all occurrences of the $ sign
As the title states, I have a C# console app which uses interop to
as the questions title says - I need to know what is the best
As the title states, I would like to know, before writing a join, if
Not sure if I've worded my title correctly but here goes. I have a
As the title states, I am using devise. I came upon this link that
As the title states, if I don't clean my project before building, neither the
As the title states, I'm trying to resize a Texture2D before even considering SpriteBatch.Draw()

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.