Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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
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
It's not a secret anymore!