Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

moving circle problem!

 
mskhawal
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everybody,
i am new to java and i am trying to move a circle from one to another end in the applet horizontally using threads. The problem is that after repaint(), the paint() should be called. But how the position is increment ie., x-axis is the problem.
plz solve my problem
khawal
 
Daniel Searson
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont have the specifics of what you are doing but I would keep a couple of private variables x and y. x starts at 0 and y starts at getHeight() / 2.
In run(), increment x by 10 (or some other value), then call Thread.sleep() for a bit, then repeat (using while loop). Dont forget to call repaint() each time that the x value changes.
Hope that helps.
------------------
- Daniel
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"mskhawal",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please choose a new name which meets the requirements.
Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic