This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Hi,
I have calss JPButton that extends JButton. It basically is a graphical button that shifts 1 pixel to the right and down when mousePressed(), and shifts back when mouseReleased(). Both of those functions are Overriden obviously. The question I have is that I'm trying to have a keypress mimick the Mouse action. I attempted to do this by Overriding doClick(). Doesn't seem to work. Is there a preferred way to do this?
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
you move all of the code from inside mousePressed/released/whatever to separate methods,
called from mousePressed/released/whatever. Those methods can now be called from your
keyListener methods.
Tim Alvord
Greenhorn
Joined: Jan 24, 2013
Posts: 22
posted
0
Michael,
Did that. Same result. It executes the code, but the button doesn't move when called from doClick()...
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
2
Thread.sleep(500L);
will block any painting/listening - use a Swing.Timer for delay purposes