Results 1 to 4 of 4
  1. #1
    karabo101 is offline Member
    Join Date
    Apr 2009
    Posts
    14
    Rep Power
    0

    Post adding eventhandler

    /*import the required packages*/
    import java.awt. * ;
    import java.awt.event. * ;
    public class ValidateEvent extends EventObject implements ActionListener
    {
    public String username, password;
    public ValidateEvent (Object o, String username, String password)
    {
    super (o);
    this.username = username;
    this.password = password;
    }
    }
    public interface ValidationListener extends EventListener
    {
    public void Validation (ValidateEvent val);
    /* Display message */
    If (temp1.equals(temp2)
    JOptionPane.showMessageDialog ( this, new
    string(“Please enter correct login details”) ;
    else
    JOptionPane.showMessageDialog (this,new
    String(“ You have entered the correct Login Details,Thank you”));
    }
    }

    am tryin to create an event handler to display 1 of the above messages if the user enters wrong or correct details while login. Am i on the right track? aasssist please whare possible by giving examples in relation to what i am trying to do.PLEASE NOTE I AM NEW TO JAVA.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You may be over-complicating things perhaps unnecessarily. Are you sure that you want to create your own new EventObject-extending class and Listener class? Have you first tried using a tried-and-true ActionListener added to a button?

  3. #3
    karabo101 is offline Member
    Join Date
    Apr 2009
    Posts
    14
    Rep Power
    0

    Default

    i hav worked with buttons b4,i am tryin to display a message if any of the conditions is met.can i get help on how i can do that.mayb a snipped showing how a dialog box can be shown

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    For a small listener like this, I would use an anonymous inner class as my ActionListener, and then when the button has been pressed, query the "this" object to see the state of the conditions, and based on this, display the appropriate dialog.

    If you have to use a separate listener class, and you are using an MVC pattern then you could pass a reference of the current model to the listener and in the actionPerformed method ask the model its state and show a dialog based on the model's response. This of course is a more complex solution.

Similar Threads

  1. Adding
    By natep67 in forum New To Java
    Replies: 2
    Last Post: 04-22-2009, 08:51 AM
  2. [new] need help on GUI adding images
    By counterfox in forum AWT / Swing
    Replies: 5
    Last Post: 03-19-2009, 11:29 AM
  3. adding GUI to Inventory
    By voyager91 in forum New To Java
    Replies: 8
    Last Post: 02-01-2009, 06:20 AM
  4. adding thread
    By amith in forum Java 2D
    Replies: 0
    Last Post: 07-05-2008, 05:33 PM
  5. adding thread
    By amith in forum Java 2D
    Replies: 0
    Last Post: 07-05-2008, 05:31 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
  •