Results 1 to 4 of 4
  1. #1
    dalu is offline Member
    Join Date
    Mar 2011
    Posts
    23
    Rep Power
    0

    Default Create an event programatically

    HI,
    I dont know if this question seems to be stupid. I am involved in customisation of some java codes, and I have a class named privateClass with an action performed method.
    class privateClass{
    ........................
    ........................
    public void actionPerformed(ActionEvent e)
    {
    String command = e.getActionCommand().trim();
    if(command.equals("Back"))
    {
    perform();
    }
    .............
    ..............
    }
    .............
    ...........
    }


    I want to execute the method perform() and so I want to generate event manually with action command as "Back". I dont have a GUI component here to create an event . Since the perform() method is a private one, I cant use it externally. Please help me. If the idea seems to be insane and you have a better one to achieve this requirement, please do suggest.

    Regards,
    Dalu

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    You don't say if you have written this code. If so you should change the name to PrivateClass. (in fact you should choose a name that describes what the class is).

    I want to generate event manually with action command as "Back"
    You can create an instance of ActionEvent using its constructor.

    If the idea seems to be insane and you have a better one to achieve this requirement, please do suggest.
    I'm not sure I know what the requirement is: ie what you are trying to do rather than how you are trying to do it. Synthesising an event is a bit fishy on the face of it. In particular the code you present as "..." may well do things with the event argument you pass.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    After you create the ActionEvent object, you can call the actionPerformed() method with that AE object.
    To what component/object has the actionPerformed() method been added as a listener?
    You can call that component's get...Listeners() method to get a reference to the listener so you can call it.

    The call will be on your thread so be aware of that. Perhaps you might want to create a new thread to make the call.

  4. #4
    dalu is offline Member
    Join Date
    Mar 2011
    Posts
    23
    Rep Power
    0

    Default

    I used the constructor and that was what I exactly needed. Thanks.

Similar Threads

  1. Replies: 1
    Last Post: 05-05-2011, 10:23 PM
  2. How to create Table programatically in JSF.
    By JavaEmpires in forum JavaServer Faces (JSF)
    Replies: 2
    Last Post: 06-25-2008, 11:27 AM
  3. How to create widgets on some event
    By sarbuland in forum Advanced Java
    Replies: 0
    Last Post: 02-06-2008, 08:08 PM
  4. Creating an appointment programatically
    By coatsy in forum New To Java
    Replies: 3
    Last Post: 01-08-2008, 06:18 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
  •