Gaurav
Gaurav

Reputation: 55

Calling a function in java by clicking on menu item

Am designing an application in java using netbeans, in which i need to call a "Save" function by clicking on the save item on the menu bar. Am able to call the function by having a button inside the main panel, but am not able to call the function when i click on the menu bar or any where else. How can this be done?

Upvotes: 0

Views: 2096

Answers (2)

trashgod
trashgod

Reputation: 205875

Start with How to Use Menus, then see this example of How to Use Actions.

Upvotes: 1

Rakesh
Rakesh

Reputation: 4334

First check if you have defined an actionPerformed() method for the menuitem from which you are trying to call the method. If not, then you can define an actionPerformed() method by right clicking on the menu item in the design frame and select "events>actionperformed" from the context menu. Also take care that the menu items objects should not be a static field.

Upvotes: 1

Related Questions