Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

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
43
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
 
You’ll find me in my office. I’ll probably be drinking. And reading this tiny ad.
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!