Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

adding actionlistener to menuItem

843805Oct 17 2005 — edited Oct 18 2005
hi...i'm trying to add an actionListener to a menuItem. i looked at the tutorial on "how to use menus" but i cant seem to execute the menuitem. here's my code...
public class Controller implements ActionListener
{
    GUI gui;
    public Controller(GUI g)
    {
        gui = g;
        gui.menuItem.addActionListener(this);
        
    }
    
    public void actionPerformed(ActionEvent e)
    {
        gui.menuItem = (JMenuItem)(e.getSource());
        if (gui.menuItem.getText().equals("New Database"))
            System.out.println("Hello");
    }
}
where the class GUI is where the menItems have been added to the menus. i'm just trying out for one menuItem first but i wont get the "hello" printed on the screen...can someone give me some assistance on this given that i havent used JMenuItems before...thx in advance...
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 15 2005
Added on Oct 17 2005
3 comments
373 views