package 线程优先级;
import java.awt.*;
import javax.swing.*;
public class MyThread extends JFrame{
static private Thread thread[]=new Thread[4];
static int k=0;
public MyThread(String title)
{
super(title);
Container container=this.getContentPane();
container.setLayout(null);
JProgressBar pb[]=new JProgressBar[4];
for(int i=0;i<4;i++)
{
pb[i]=new JProgressBar();
pb[i].setStringPainted(true);
}
for(k=0;k<4;k++)
{
thread[k]=new Thread(new Runnable(){
public void run()
{
for(int i=0;i<=100;i++)
{
try{
Thread.sleep(100);
}catch(Exception e)
{
e.printStackTrace();
}
** pb[k].setValue(i);** //这句话似乎是错误的
}
}
}
);
}
thread[0].setPriority(5);
thread[1].setPriority(5);
thread[2].setPriority(4);
thread[3].setPriority(3);
for(int i=0;i<4;i++)
thread[i].start();
this.setSize(400,400);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
new MyThread("线程优先级");
}
}
错误提示是数组下标越界,我没找到究竟怎么会越界的?求解