⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 runnable.java~1~

📁 数据结构综合实验,有各种排序算法和计算排序时间,最短路径算法,huffman编码解码.用图形界面实现.在jbuilder2006下运行通过.
💻 JAVA~1~
字号:
import java.awt.*;
import javax.swing.*;
import java.text.*;


public class SecondCounterRunnable extends JComponent implements Runnable{
	private volatile boolean keepRunning;
	//private boolean keepRunning;
	
	private Font paintFont;
	private volatile String timeMsg;
	private volatile int arcLen;
	
	public SecondCounterRunnable() {
		paintFont = new Font( " SansSerif" , Font.BOLD, 14);
		timeMsg = "never start ";
		arcLen = 0;
	}
	
	public void run(){
		runClock();
	}
	
	public void runClock() {
		System.out.println("thread running runClock() is " + 
			Thread.currentThread().getName());
		
		DecimalFormat fmt = new DecimalFormat ( " 0.000 ");
		long normalSleepTime = 1;
		
		int counter = 0;
		keepRunning = true;
		
		while( keepRunning ) {
			try {
				Thread.sleep(normalSleepTime);
			}
			catch(InterruptedException e) {}
		
		counter++;
		double counterSecs = counter / 10.0;
		
		timeMsg = fmt.format(counterSecs);
		
		arcLen = (((int)counterSecs) % 60 ) * 360 / 60;
		repaint();
		}
	}
	
	public void stopClock() {
		keepRunning = false;
	}
	
	public void paint(Graphics g) {
		System.out.println( "thread that invoked paint() is" + 
			Thread.currentThread().getName());
		
		g.setColor(Color.red);
		g.setFont(paintFont);
		g.drawString(timeMsg,0,15);
				
		g.fillOval(0,20,100,100);
		
		g.setColor(Color.orange);
		g.fillOval(3,23,94,94);
		
		g.setColor(Color.blue);
		g.fillArc(2,22,96,96,90, -arcLen);
	}
}


	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -