📄 e1504.java
字号:
import javax.swing.*;
import java.awt.*;
public class E1504 extends JFrame
{
private static RandomThread thread1=null;
private static RandomThread thread2=null;
private static RandomThread thread3=null;
private Container c;
private JTextField[] text=new JTextField[3];
public E1504()
{
super("E1504.java:RandomThread测试!");
c=getContentPane();
text[0]=new JTextField("",10);
text[1]=new JTextField("",10);
text[2]=new JTextField("",10);
c.setLayout(new FlowLayout());
c.add(text[0]);
c.add(text[1]);
c.add(text[2]);
thread1=new RandomThread(1);
thread2=new RandomThread(2);
thread3=new RandomThread(3);
thread1.start();
thread2.start();
thread3.start();
setSize(400,100);
setVisible(true);
}
private class RandomThread extends Thread
{
int sleepTime,index,Num;
String str;
String[] strArray={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
public RandomThread(int id)
{
sleepTime=(int)(Math.random()*1000);
Num=id;
}
public void run()
{
while(true)
{
try
{
index=(int)(Math.random()*26);
str=strArray[index];
text[Num-1].setText("执行者"+Num+":"+str);
Thread.currentThread().sleep(sleepTime);
}
catch(InterruptedException e)
{System.out.println("Exception="+e.toString());}
}
}
}
public static void main(String args[])
{
E1504 app=new E1504();
app.addWindowListener(new MyWindowListener());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -