Results 1 to 7 of 7

Thread: ActionListeners

  1. #1

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Resolved ActionListeners

    I need to respond to a press on a JButton in a JApplet. I've tried adding implements actionlistener but I get the "Class is not abstract" error. How do you implement an actionlistener in a JApplet?
    Last edited by Nove; Jun 18th, 2005 at 11:07 AM.

  2. #2
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: ActionListeners

    add the actionListener to the button:
    Code:
    ButtonName.addActionListener(this);
    then override the actionPerformed method:
    Code:
    public void actionPerformed(ActionEvent ae)
    {
            if (ae.getSource() == ButtonName)
            {
                   //Do something
            }
    }

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: ActionListeners

    Code:
     import java.awt.event.*;
     import java.applet.Applet;
    
     class MyApplet extends Applet implements ActionListener{
    
      public void actionPerformed(ActionEvent evt){}
    
     }

  4. #4
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: ActionListeners

    The reason why you get that MyApplet is not abstract and does not overide abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener is simply that you must either override all abstract methods from the interface or declare your class abstract.

  5. #5

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: ActionListeners

    Oh, so all I had to do to override it was to change the variable name?

  6. #6
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: ActionListeners

    perhaps you can show us your code?

  7. #7

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: ActionListeners

    No need, System_Error had the answer, I was just wondering. Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width