File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Selecting A Menu Item Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Selecting A Menu Item" Watch "Selecting A Menu Item" New topic
Author

Selecting A Menu Item

simon keillor
Greenhorn

Joined: Jun 23, 2004
Posts: 24
Hi,

Have created a frame with a nice menu on it and hav added a popup menu as well.

Now how do I get my app to respond to someone clicking on a menu item? Am armed with my 'Teach Yourself Java In 21 Days' bible but doesn't cover this.

Thanks

Simon


Simon
Steve JK
Greenhorn

Joined: Jun 16, 2004
Posts: 5
Hi Simon,

for each menu item you have, do the following:

menuItem.addActionListener(this);

where you substitute 'menuItem' for the actual name of your menu item, then

public void actionPerformed(ActionEvent e)
{
if(e.getSource==menuItem)
{
//..code to do whatever
}
}


That should work for you

Cheers,
Steve


Happy Coding all!
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Swing / JFC / AWT forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
GeeCON Prague 2014
 
subject: Selecting A Menu Item