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

📄 testrunnable.java

📁 针对越来越多的用户喜欢JAVA
💻 JAVA
字号:
import java.applet .Applet ;
import java.awt .* ;
public class TestRunnable extends Applet implements Runnable 
{
	Label prompt1=new Label("第一个子线程");
	Label prompt2=new Label("第二个字线程");
	TextField threadFirst=new TextField (14);
	TextField threadSecond=new TextField (14);
	Thread thread1,thread2;
	int count1=0,count2;
        public void init()
	{
		add(prompt1);
		add(threadFirst);
		add(prompt2);
		add(threadSecond);
	}
	
	public void start()
	{
		thread1=new Thread(this,"FirstThread");
		thread2=new Thread(this,"SecondThread");
       		thread1.start();
		thread2.start();
	}
	public void run()
	{
		String curRunning;
		while(true)
		{
			try
			{
				Thread.sleep((int)(Math.random()*3000));
                 	}
			catch(InterruptedException e){}
			curRunning=Thread.currentThread ().getName();
			if(curRunning.equals ("FirstThread"))
			{
				count1++;
                                threadFirst.setText ("线程1第"+count1+"次被调度");
			}
			else if(curRunning.equals ("SecondThread"))
			{
				count2++;
				threadSecond.setText ("线程2第"+count2+"次被调度");
			}
		}   
	}
}

⌨️ 快捷键说明

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