This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes JMenu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JMenu" Watch "JMenu" New topic


Lei Xiaowen

Joined: Jul 11, 2005
Posts: 15
1. JMenu menuInfo=new JMenu();

3. JMenuItem itemShow=new JMenuItem("信息综合管理");
4. itemShow.addItemListener(ItemListener I);
5. menuInfo.add(itemShow);

at line 4 "add ItemListener "is wrong,why?
the correct code is what?
thanks a million!
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
The notation in the method signature addItemListener(ItemListener I) is a way of saying that the argument I must be of type ItemListener. For line 4 you want to put a reference to/or the actual listener in as the argument. We have lots of options for this, such as

You would use the method signature as given
public void addItemListener(ItemListener I) {
if you wanted to override it inside a class that extends JMenuItem.
I agree. Here's the link:
subject: JMenu