import java.awt.*; //import gjt.Stopwatch; //import gjt.StopwatchClient; public class MovingBar extends Bargauge implements Runnable{ Thread m_MovingBar; Image m_image; Graphics m_g; Rectangle m_dimImage = null; //Stopwatch m_timer=new Stopwatch(this); int m_tickCount=0; int gridCount=9; boolean grid=false; public Color secondFill=Color.blue; public double addedFill=0.0; public MovingBar(Color fillColor){ super(fillColor); //((Thread)m_timer).start(); } protected void ResizeImage(){ Rectangle dim = border.getInnerBounds(); int nWidth = dim.width; int nHeight = dim.height; if (nWidth<2 || nHeight<2) return; if (m_dimImage != null && m_dimImage.width == nWidth && m_dimImage.height == nHeight){ return; } m_dimImage = new Rectangle(dim.x,dim.y,nWidth, nHeight); m_image = createImage(nWidth, nHeight); m_g = m_image.getGraphics(); m_g.setColor(getBackground().darker()); int j; if (nWidth>nHeight){ for (j=0; j0) || (addedFill>0)){ if (x1>=y1){ m_g.copyArea(0,0,x1,y1,-1,0); if (grid) m_g.setColor(getBackground().darker()); else m_g.setColor(getBackground()); m_g.drawLine(x1-1,0,x1-1,y1); if (grid) m_g.setColor(fillColor.darker()); else m_g.setColor(fillColor); m_g.drawLine(x1-1,y1,x1-1,y1-y1*(int)percentFill/100); if (grid) m_g.setColor(secondFill.darker()); else m_g.setColor(secondFill); m_g.drawLine(x1-1,y1-y1*(int)percentFill/100,x1-1,y1-y1*(int)percentFill/100-y1*(int)addedFill/100); m_g.setColor(getBackground().darker()); for (j=0;jx1*(int)percentFill/100) m_g.setColor(getBackground().darker()); else m_g.setColor(fillColor.darker()); m_g.fillRect(j,0,1,1); } } } } public void tick(){ m_tickCount = (++m_tickCount)%20; if (m_tickCount == 0) repaint(); } public void reshape(int x, int y, int w, int h){ super.reshape(x,y,w,h); ResizeImage(); } public void start(){ if (m_MovingBar == null) { m_MovingBar = new Thread(this); m_MovingBar.start(); } //if (m_timer != null){ // stop(); //} //m_timer=new Stopwatch(this); //((Thread)m_timer).start(); } public void stop(){ if (m_MovingBar != null) { m_MovingBar.stop(); m_MovingBar = null; } //m_timer.stopit(); //((Thread)m_timer).stop(); //setFillColor(Color.white); //m_timer=null; } public void run() { while (true) { try { repaint(); Thread.sleep(1000); } catch (InterruptedException e) { // TODO: Place exception-handling code here in case an // InterruptedException is thrown by Thread.sleep(), // meaning that another thread has interrupted this one stop(); } } } }