how do i check if a menu item in my JMenuBar has been clicked? for instance, i have a JMenu with an item called exit, which i need to make close the form. how do i do this?

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);

    }

}

Well it depends on who is seeing it... the admin knowing who clicked the links or the user knowing what links they have clicked?

If it's the users, play with the css for the links... sorry if it is not javascript... i personally don't what exactly is going on...

Michael, thisis java code not javascript and this is the code for a "JForm" using javax.swing.

as ire;ivant as your answer is, if i wanted to control who clicked a mouse on a webpage, i would return the clientside address using ajax and write a wrapper for a:onclicked, which is a sub process of the a tag. -irrelivant tangent-

Normally you add a listener to the items you want to be able to receive notice of events like clicks.

I am sorry, my mind is quite dead this past week...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.