Results 1 to 12 of 12
  1. #1
    Wesley Chin is offline Member
    Join Date
    Apr 2010
    Posts
    14
    Rep Power
    0

    Default Multi event listeners

    Hi everyone,

    I have a bit of a problem. I am trying to use the multi event listeners but keeping getting this error:

    cannot find symbol
    symbol: class EavesDropper
    location: class aloeandcycaddatabasegui.AloeAndCycadDatabaseLogin
    --
    (Alt-Enter shows hints)


    The first action listener works 100% but I am battling with this one.

    Here is some of the code that I have:

    // Adding the action listener to the button
    loginBtn.addActionListener(this);
    loginBtn.addActionListener(new EavesDropper(loginBtn));

    // The Eavesdropper class
    class Eavesdropper implements ActionListener {

    JButton loginBtn;

    public Eavesdropper(JButton lb) {
    loginBtn = lb;
    }

    public void actionPerformed(ActionEvent e) {
    }
    }

    I have also imported these packages:

    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    import javax.swing.*;
    import java.awt.event.ActionEvent;

    Any help is greatly appreciated

  2. #2
    Wesley Chin is offline Member
    Join Date
    Apr 2010
    Posts
    14
    Rep Power
    0

    Default

    No suggestions? :(

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,955
    Rep Power
    8

    Default

    Eavesdropper != EavesDropper.

  4. #4
    Wesley Chin is offline Member
    Join Date
    Apr 2010
    Posts
    14
    Rep Power
    0

    Default

    Thanks Kevin, that was really dumb on my part!

  5. #5
    Wesley Chin is offline Member
    Join Date
    Apr 2010
    Posts
    14
    Rep Power
    0

    Default

    Hi guys,

    I am getting a null pointer exception when I try and use the login button. Is there a way to fix this? I have attached the file so you guys can see what I am doing. I think the problem is in the EavesDropper class but I don't know how to fix it.

    Any help is appreciated.

    Thanks in advance,
    Wesley
    Attached Files Attached Files

  6. #6
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    For future reference please try not to post full projects... make a small, simple, compileable and correct program which contains as little as neccesary to reproduce the error.

    Also, when you describe the errors please copy the full stack trace and the offending lines of code.

    As is stands, i cannot run your code straight away, as you didnt include the picture file.

    I managed to get round that by not making the picture, and this is the second null pointer i came accross: it might not be the one you are experiencing - im just guessing :P

    anyway, the stack is:
    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
            at aloeandcycaddatabasegui.AloeAndCycadDatabaseLogin.actionPerformed(AloeAndCycadDatabaseLogin.java:236)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
            at java.awt.Component.processMouseEvent(Component.java:6267)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
            at java.awt.Component.processEvent(Component.java:6032)
            at java.awt.Container.processEvent(Container.java:2041)
            at java.awt.Component.dispatchEventImpl(Component.java:4630)
            at java.awt.Container.dispatchEventImpl(Container.java:2099)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
            at java.awt.Container.dispatchEventImpl(Container.java:2085)
            at java.awt.Window.dispatchEventImpl(Window.java:2478)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    The offending code is
    Java Code:
    String firstname = fNameTF.getText();
    Make sure fNameTF.getText() is not null (hence null pointer exception).

    Your actionPeformed seems to only deal with the situation where the user is not registered. You need to account for when they are logging in, not registering.

  7. #7
    Wesley Chin is offline Member
    Join Date
    Apr 2010
    Posts
    14
    Rep Power
    0

    Default

    Thank your for the reply. i will make sure to do that next time. That is the same error that I am getting. Can you please tell me how I can rectify it? I dont know how it points to the firstname as I told it to pint to only the username and password fields in the login screen.

  8. #8
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    Its difficult to say exactly how as i dont fully understand your code.

    As far as i can tell, you have two "screens" - one for logging in and one for registering.

    In your action listener you could put something like
    Java Code:
    if (registering) {
        // deal with registering the user
    
        String firstname = fNameTF.getText();
        String lastname = lNameTF.getText();
        String age = ageTF.getText();
        String country = countryTF.getText();
        String username = usernameTF.getText();
        String password = new String(passwordTF.getPassword());
        // etc
    } else {
        // deal with logging in
    }
    where the boolean value "registering" is defined when the user clicks the "yes" or "no" button when asked if they are registered.

  9. #9
    Wesley Chin is offline Member
    Join Date
    Apr 2010
    Posts
    14
    Rep Power
    0

    Default

    I know exactly what you mean, but dont know how to code it. Could you help me please by showing me what to do more or less?

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,997
    Rep Power
    19

    Default

    berkeleybross has given you plenty to work with.
    Aren't you going to even give it a go?

  11. #11
    Wesley Chin is offline Member
    Join Date
    Apr 2010
    Posts
    14
    Rep Power
    0

    Default

    Thanks guys, I got it to work. I have just started out with Java so I am not too familiar with everything but I managed to decipher everything :)

  12. #12
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

Similar Threads

  1. Drag and Drop disables Event Listeners?
    By qwerty4030 in forum AWT / Swing
    Replies: 1
    Last Post: 10-01-2010, 04:36 AM
  2. Seriously need help on my listeners!!
    By themburu in forum Java Applets
    Replies: 4
    Last Post: 05-26-2008, 10:41 AM
  3. Multiple listeners per event
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 01-03-2008, 10:06 AM
  4. Action Event and Listeners
    By lost1 in forum New To Java
    Replies: 3
    Last Post: 11-14-2007, 04:26 AM

Posting Permissions

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