FileDocCategorySizeDatePackage
Spinner.javaAPI DocExample2589Wed Apr 19 11:22:00 BST 2000actual

Spinner

public class Spinner extends Component
Spinner - a class that creates a lightweight component that shows a spinning wheel. Lightweight components can have "transparent" areas, meaning that you can see the background of the container behind these areas.

Fields Summary
float
percentDone
int
totalTicks
int
currentTick
SpinnerThread
spinnerThread
Constructors Summary
public Spinner()
Constructs a Spinner

  
        
    
      setForeground(Color.gray);
      setForeground(Color.lightGray);
  
Methods Summary
public intgetCurrentTick()

      return currentTick;
  
public intgetTotalTicks()

      return totalTicks;
  
public voidpaint(java.awt.Graphics g)
paints the Spinner

      int start_angle = 90;
      int done_angle = (int) (percentDone * 360);
      
      g.setColor(getBackground());
      g.fillArc(3, 3, getSize().width-8, getSize().height-8, 0, 360);
      
      g.setColor(getForeground());
      g.fillArc(3, 3, getSize().width-8, getSize().height-8, start_angle, done_angle);

      g.setColor(Color.black);
      g.drawArc(3, 3, getSize().width-8, getSize().height-8, 0, 360);
  
public voidsetCurrentTick(int tick)

      currentTick = tick;

      if(currentTick > totalTicks) {
	  percentDone = 1;
      } else if(currentTick == 0) {
	  percentDone = 0;
      } else {
	  percentDone = (float) currentTick / (float) totalTicks;
      }
      
      // Repaint might flicker a bit. To avoid this, you can use
      // double buffering (see the Gauge example).
      repaint();
  
public voidsetTotalTicks(int tick)

      totalTicks = tick;
  
public voidstartSpinning()

      spinnerThread = new SpinnerThread(this);
      spinnerThread.start();
  
public voidstopSpinning()

      spinnerThread.stop();
      spinnerThread = null;