   Distance Bar in Golf Game (java)
   Hi there,I am trying to create a simple golf game and want to make a bar that moves up and down and the player will click the bar to make it start moving (or it could always be moving) and then they click it again to make it stop. The place it stops will be represented by a number in the code so should be in a variable.I was wondering if anyone knew of any ways in which I could achieve this. I have some basic code which allows the user to move a filled rectangle up and down using a scroll bar:import java.awt.*;import java.applet.Applet;import java.awt.event.*;public class DistanceBar extends Appletimplements AdjustmentListener {private Scrollbar slider;private int sliderValue;public void init () {slider = new Scrollbar(Scrollbar.VERTICAL, 0, 1, 0, 101);add(slider);slider.addAdjustmentListener(this);}public void paint (Graphics g) {showStatus("Scrollbar value is " + sliderValue);g.drawRect(40, 80, 60, 100);g.fillRect(40, 80, 60, sliderValue);}public void adjustmentValueChanged(AdjustmentEvent e) {sliderValue = slider.getValue();repaint();}}Many thanks. 
  Well, my main purpose of this reply is to say that Donnie Darko   rocks!But to try to be helpful...  I don''t know much ''bout Java (learned it in college, but didn''t use it much, so my experience is just about nil), but in general, it sounds like you need a timer object of some sort.  My guess is that the Java library provides a fairly simple timer that repeatedly raises an event every few milliseconds, and then you can act on that event just like you did with the scrollbar event.  Google for it and you might find something useful. ;  To be a little more directly helpful, go look up the Javadocs for the standard library on Sun's website (very easy to find there for Standard Edition) and look up the classes "Timer" and "TimerTask".   [edited by - Zahlman on February 4, 2004 3:04:54 PM]