• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to simulate a button click

 
Brian Percival
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JButton, which has a setActionCommand and setActionListener.
When I click on the button the event is generated and is handled by the actionListener.
How can I generate the event programmatically as if the button is really pressed?


regards,
Brian
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
button.doClick();

an alternative is to move the code from actionPerformed into a separate method
and call the method from actionPerformed(). You can then call the same method
from other parts of the program.
 
Brian Percival
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My actual problem was, to access the local file system in an applet. I found the code on the net, signed it and it works fine. But when I do the equivalent of what the code si doing in my own public method, creating new file and all, I get a permission denied exception. Any pointers regarding this?

doClick is raising the event. However, the security system is somehow aware of the execution comes to the actionPerformed().

When I do a click on the browser, the file is accessed fine. But when I do it thru a doClick call in my public method, I get a permission denied exception. Smart!! But what is the workaround??

regards,
Brian
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic