• Post Reply Bookmark Topic Watch Topic
  • New Topic

Wrapper Classes  RSS feed

 
shriram raj
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
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!