• 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

abstract problems

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
alright. the message im getting is "garden" is not an abstract method and can't override abstract method actionPreformed(java.~~~.event.Actionevent) im just trying to get my buttons to work.any help would be greatly appriciated.


code:




Edit: just incase this needs to be noted, im working in BlueJ.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peter, welcome to the ranch.

If your class implements ActionListener, you must implement all methods of that interface. There's only one method in that interface, actionPerformed, so you have to implement it, and use "quitItem.addActionListener(this);".

Or, you can just remove the "implements ActionListener" part, and leave your code as is. But as many buttons will be using your ActionListener, so I think you should leave "implements ActionListener", and implement the actionPerformed method.

The important thing to remember is that you need to pass an ActionListener to the addActionListener method. You can choose to create an anonymous class, like you did by having new ActionListener() in addActionListener. Or you can choose to implement ActionListener and pass your class to addActionListener.

PS: Next time you post code, please UseCodeTags to make your source more readable.
 
peter chapman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
......im lost now. any code examples on what you mean?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have the following code :

which means that you are implementing the ActionListener interface. Unless your Garden class is abstract (but it's not), you must implement this interface's methods. Look at the API for ActionListener (<-- click the class name). You'll see that there is a method called "actionPerformed". You must implement it. In other words, you need to have "public void actionPerformed(ActionEvent e)" in your Garden class.
 
peter chapman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wow..... after google it the first time i did that, and it didn't work. but now it does. thank you very much! as to why it didn't work the first time, who knows.....
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch (again).

It is possibole you had a tiny spelling errror in your first atttempt. Whenever you are overriding a method (or in Java 6 implementing a method from an interface), put the @Override annotation before the method heading. Then you get a compiler error like "doesn't override a superclass method" if there is a spelling error.
Since you are new, I'll add code tags and you can see how much better the code looks.
reply
    Bookmark Topic Watch Topic
  • New Topic