Results 1 to 2 of 2
  1. #1
    barney is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default Error: javax.swing.AbstractButton cannot be applied to...

    Hi, iv written a program which has a JtabbedPane GUI but the problem is on one of my tabs i have a JPanel called panel1. on panel1 i have a button called addButton now i add this button onto my panel and my panel onto the tab using the following code:
    Java Code:
    panel1.add(addButton);
    tabbedPane.addTab("New Booking", null, panel1, "First Panel");
    which works just fine and when compiled you see the tabs and the button on the first pane.

    but then when i try and ad an actionlistener to the button using the following code
    Java Code:
      addButton.addActionListener(this);
    i get this error:
    Java Code:
    addActionListener(java.awt.event.ActionListener) in javax.swing.AbstractButton cannot be applied to (tester) 
    tester is the name of my class.
    Thanks

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    tester must implement ActionListener and have its only method implemented:
    Java Code:
    class tester implements ActionListener {
        ...
        public void actionPerformed(ActionEvent e) {
    
        }
        ...
    }
    in order to be a proper ActionListener for addButton.

Similar Threads

  1. Replies: 7
    Last Post: 07-12-2010, 04:24 PM
  2. javax.microedition.io/ javax.bluetooth
    By ahtiven in forum New To Java
    Replies: 3
    Last Post: 01-13-2009, 02:54 PM
  3. Error: javax.servlet.ServletException: Column not found
    By barney in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 08-07-2007, 07:20 AM
  4. Error: cannot be applied to (java.lang.String)
    By carl in forum New To Java
    Replies: 1
    Last Post: 08-05-2007, 06:33 AM
  5. map javax.swing.text.Element to javax.swing.text.View
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 07:02 PM

Posting Permissions

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