• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JMenu

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello:
//
1. JMenu menuInfo=new JMenu();
2.mainMenu.add(menuInfo);

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!
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
This one time, at bandcamp, I had relations with a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic