This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I have one doubt? that is if i want to move a small rectangle along with x-axis,what am i suppose to do? any idea?
Joined: Feb 23, 2007
srinivas miriyala wrote:I have one doubt? that is if i want to move a small rectangle along with x-axis,what am i suppose to do? any idea?
Right now, because you draw the rectangle using int literals (10, 10, 200, 200), it is hard-coded to have its left upper corner located at [10, 10], relative to the JComponent it sits in. If you want to move the rectangle, you're along the x axis, you're going to have to use a variable for the first parameter of drawRect, change that variable in a Swing Timer, and call repaint on the MyCanvas object after changing the variable.