Results 1 to 4 of 4
  1. #1
    JOHNINALBANY is offline Member
    Join Date
    Nov 2010
    Posts
    17
    Rep Power
    0

    Default EventHandler issue

    If I click on the "Event Handler" button the following error is reported:

    Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: No method called LoadData on class MyFrame with no arguments
    ...more...

    There is a non-arg LoadData method in MyFrame, no? What am I missing here?



    ------code-------

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    //import java.awt.EventQueue.*;
    import java.beans.*;



    public class TestingEventHandler {

    TestingEventHandler(){
    MyFrame frame = new MyFrame("My Frame");
    JPanel panel = new JPanel();
    JButton button = new JButton("Event Handler");


    panel.add(button);



    frame.add(panel);

    System.out.println(frame.LoadData());

    button.addActionListener(EventHandler.create(Actio nListener.class,frame,"LoadData")); //this statement triggers an error


    }


    public static void main(String[] args) {
    // TODO code application logic here
    TestingEventHandler tvh = new TestingEventHandler();
    }

    }


    class MyFrame extends JFrame{
    MyFrame(String Title){
    super(Title);
    setSize(300,300);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
    }

    String LoadData(){
    return("you have clicked on a button");
    }

    }

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,068
    Blog Entries
    3
    Rep Power
    14

    Default

    Perhaps it's the fact that you say Actio nListener, try removing the space.

    Looking at the API for EventHandler shows this
    Java Code:
    myButton.addActionListener(
        (ActionListener)EventHandler.create(ActionListener.class, frame, "toFront"));
    Try using this code and substituting your values.

  3. #3
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    10

    Default

    The only possible way that exception could be thrown is if you didn't compile all the classes before running it. ;)

  4. #4
    JOHNINALBANY is offline Member
    Join Date
    Nov 2010
    Posts
    17
    Rep Power
    0

    Default Re: EventHandler issue

    Sorry for the delay. Thanks for your valuable help.

Similar Threads

  1. another tic tac toe issue
    By hoangx87 in forum New To Java
    Replies: 3
    Last Post: 04-18-2011, 10:26 AM
  2. JSP issue
    By RamaLakshmi in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 01-21-2011, 01:55 PM
  3. Same issue as before....
    By hayden06f4i in forum New To Java
    Replies: 4
    Last Post: 11-08-2010, 01:49 AM
  4. adding eventhandler
    By karabo101 in forum New To Java
    Replies: 3
    Last Post: 05-20-2009, 11:38 PM
  5. Issue
    By chaitu444 in forum New To Java
    Replies: 2
    Last Post: 11-06-2007, 07:49 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
  •