我有一个包含面板的 mainFrame。只要应用程序正在运行,我希望在此面板中更改标签图像的线程...
当我创建实现可运行的面板,然后在大型机中创建此面板的一个实例时,应用程序进入无限循环......我的代码如下:
public mainFrame()
{
BanerPanel baner = new BanerPanel();
baner.run();
}
public class Banner_Panel extends JPanel implements Runnable {
public Banner_Panel() {
initComponents();
imgPath = 2;
imgLbl = new JLabel(new ImageIcon(getClass().getResource("/Photos/banner_4-01.png")));
add(imgLbl);
//run();
}
@Override
public void run() {
while(true)
{
try {
while (true) {
Thread.sleep(3000);
switch(imgPath)
{
case 1:
imgLbl.setIcon(new ImageIcon(getClass().getResource("/Photos/banner_4-01.png")));
imgPath = 2;
break;
case 2:
imgLbl.setIcon(new ImageIcon(getClass().getResource("/Photos/banner_1-01.png")));
imgPath = 3;
break;
case 3:
imgLbl.setIcon(new ImageIcon(getClass().getResource("/Photos/banner_2-01.png")));
imgPath = 4;
break;
case 4:
imgLbl.setIcon(new ImageIcon(getClass().getResource("/Photos/banner_3-01.png")));
imgPath = 1;
break;
}
}
} catch (InterruptedException iex) {}
}
}