abstract class


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: abstract class

  1. #1
    just a beginner Guest

    abstract class


    why do i always get an error when i want to implement ActionListener??

    this is what i got:

    public class lf extends JApplet implements ActionListener{

    i get this error:

    "Class lf must be declared abstract. It does not define void actionPerformed(java.awt.event.ActionEvent)
    from interface java.awt.event.ActionListener."

    if anyone knows the answer, plz reply to me, and can u kindly also give me
    the solution!

    finally, can i do this:

    public class lf extends JApplet implements ActionListener, ItemListener{

  2. #2
    Ako Guest

    Re: abstract class


    When a class implements an interface it must define all the methods declared
    in the interface if you want to create objects of that class. The solution
    is easy just define the method inside lf class like this:

    public void actionPerformed(ActionEvent e){
    //do what you want
    }

    Yes public class lf extends JApplet implements ActionListener, ItemListener{}
    is perfectly legal, in java a class can only have one immediate super class
    but it can implement as many interfaces as you want.

    Ako


    "just a beginner" <unique_2k1@hotmail.com> wrote:
    >
    >why do i always get an error when i want to implement ActionListener??
    >
    >this is what i got:
    >
    >public class lf extends JApplet implements ActionListener{
    >
    >i get this error:
    >
    >"Class lf must be declared abstract. It does not define void actionPerformed(java.awt.event.ActionEvent)
    >from interface java.awt.event.ActionListener."
    >
    >if anyone knows the answer, plz reply to me, and can u kindly also give

    me
    >the solution!
    >
    >finally, can i do this:
    >
    >public class lf extends JApplet implements ActionListener, ItemListener{



  3. #3
    Nilendu Guest

    Re: abstract class


    You have to define a method called public void actionPerformed(ActionEvene
    t e) { write the action trapping events here}

    If this method is not there or the method signatures are not correct you
    would get this error.

    Regarding the other query, yes it is permissible.

    Nilendu

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center