I'm working with netbeans GUI and I have a menu named:file
I want this to have sub menus like:new,load,...
It seems that I should use jMenuItem,but I can not add events to it(new for example) like usual,because I added mouseClicked event,but when I click :new nothing happens.
I would be so thankful if you help me.
samira samadi wrote:I thought ActionListener is a general form and mouseListener for example th espesial one...
Definitely not. They are for two very different types of events. MouseListener is for mouse interaction in general, whereas ActionListener is for button clicks, menu item clicks, combo box changes, text field enter presses, and a whole lot more.
Just like Rob had mentioned both have different purposes. Action listener is basically for button press action. JMenuItem being a subclass of Abstract button, you can consider it as a special type of button itself. So practically all actions which can take place in button will also occur in menu item.
Sriraman Srinivasan wrote:Action listener is basically for button press action.
That's the most often use of it, but definitely not the only. Like I said, pressing enter on a JTextField or selecting an element from a JComboBox also triggers ActionEvents. javax.swing.Timer also uses it.