If I have defined JMenu
and JMenuBar
like this:
private JMenuBar jMenuBar;
private JMenu jMenu1;
jMenuBar = new JMenuBar();
jMenu1 = new JMenu();
jMenu1.setText("ABOUT");
//and here add a MenuListener so that i can detect when a menu is clicked:
jMenu1.addMenuListener(this);
jMenuBar.add(jMenu1);
setJMenuBar(jMenuBar);
//and here i implement the menulisteners
public void menuSelected(MenuEvent e) {
//my logic here
}
public void menuDeselected(MenuEvent e) {}
public void menuCanceled(MenuEvent e) {}
Now it works fine. But the problem is if i have more then one menu, how can i distinguish between the two. Like in the menu listener, how would i know the click came from menu1 or another menu 2?
I mean if i have another menu and i add menu listener for this menu as well:
jMenu2.addMenuListener(this);
then i can not distinguish from which menu the click came from. How can i do that?