This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Wrapper Classes  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
Iam involved in a work of creating wrapper classes for my
application.
Like
import mywork.awt.*;
import mywork.awt.event.*;
( i use java.awt.*;java.awt.event.* inside my package)
I use the same names as the originals namely
Button,Frame,ActionListener,ActionEvent,etc.
This is my sample file. I explain the problem after this::
import mywork.awt.*;
import mywork.awt.event.*;
public class ButtonSample extends Frame implements ActionListener
{
public ButtonSample()
{
setTitle("Button Sample");
setSize(100,100);
Button print = new Button("Print Hello");
print.addActionListener(this);
add(print);
setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
String button = ae.getActionCommand();
if (button.equals("Print Hello"))
{
System.out.println("Hello Printed");
}
}
public static void main(String []args)
{
new ButtonSample();
}
}
Actually, the program should run as i extended or implemented
the originals in my package.(mywork).
But i get a serious problem when i run this: As,
""ButtonSample.java:4: class ButtonSample must be declared abstract. It does not define void actionPerformed(java.awt.event.ActionEvent) from interface java.awt.event.ActionListener.
public class ButtonSample extends Frame implements ActionListener ""
Is there any solutuions to override these???
Thanks&Regards,
Shriram
 
author and iconoclast
Posts: 24203
40
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no idea why you'd want to provide your own like-named replacements for something like ActionListener, but I won't ask.
Anyway, because you've introduced this enormous level of confusion, you've got to introduce some serious ugliness to fix it: use the fully qualified name of every class. So since the compiler wants you to implement an actionPerformed() method with the original ActionEvent as an argument, you'll have to write it as
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!