Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Selecting A Menu Item

 
simon keillor
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Steve JK
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Swing / JFC / AWT forum...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic