• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can I create a ActionEvent to force the event happen?

 
Daniel Washington
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for example:there is a class MyFrame implements Actionlistener,so MyFrame has a method named actionPerformed(ActionEvent e),
Now,i wanna create a ActionEvent object myself and pretend the mouse itself has already clicked,so can force the clause defined in the actionPerformed()
run.
is there such a way to do this?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure if I am understanding what you are wanting to do. ActionEvents are just that. Events that happen do to an Action.
Are you wanting to automate an ActionEvent? If so, when? At what point in your application are you wanting this to happen? What are you wanting to simulate a mouse click for?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Yes, you can create the arguments and call the actionPerformed method to simulate an event.
2) Don't. Make actionPerformed call a meaningful method to do the real work, then call the same method instead of simulating the event. Now you have a nice method with a name that tells you what's really going on, and can be used with or without the original window. The code that calls the new method says what it means to do instead of messing about with arguments and event methods. The whole thing is more honest - no pretending to click imaginary mice. Neat!
[ September 16, 2003: Message edited by: Stan James ]
 
Daniel Washington
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to Gregg Bolinger &Stan James :thanks for your reply.
To Gregg Bolinger:Are you wanting to automate an ActionEvent?
Yes ,i just wanna do it.
Suppose i have complete a program,i wanna show it to else.But i do not want to copy the window at same time i do a serial of operations on my program.
I want to build such a application which can automate many Event Objects,then use it to operate that program automually.
can I success?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look into separating the part of the program that does useful work (model) from the user interface. Then you can use the same model with another user interface or an automated driver. Here's a very generalized intro to layering. Then try a google search on "java mvc" for thousands of articles on the model view controller pattern.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Swing / JFC / AWT forum...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!