kokokok
kokokok

Reputation: 479

java: activating a mouse click event

I have a java method activated by a mouse click on a button

 private void backButtonMouseClicked(java.awt.event.MouseEvent evt) { do stuff }

is there some way to virtually use this method from another method without clicking the mouse on the button?

Upvotes: 1

Views: 2370

Answers (3)

Fractaly
Fractaly

Reputation: 833

I believe you can say backButtonMouseClicked(new MouseEvent()) to call the method. Or maybe backButtonMouseClicked(null).

Upvotes: 0

camickr
camickr

Reputation: 324078

Or you can just use button.doClick();

Upvotes: 1

Zed
Zed

Reputation: 57648

Yes, MouseEvent has public constructors, so you simply create one, and call the function with it.

Upvotes: 0

Related Questions