JAVA界面编程标签闪烁

importjava.awt.FlowLayout;importjava.awt.GridLayout;importjava.awt.event.ActionListen... import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Biaoqian extends JFrame {
private JLabel b1;
private JLabel b2;
private JLabel b3;
private JLabel b4;
public Biaoqian(){
super("窗口");
setBounds(100, 100, 200, 200);
b1=new JLabel("标签1");
b2=new JLabel("标签2");
b3=new JLabel("标签3");
b4=new JLabel("标签4");
setLayout(new FlowLayout());
add(b1);
add(b2);
add(b3);
add(b4);
setLayout(new GridLayout(2,1));
setVisible(true);
}
public static void main(String[] args) {
new Biaoqian();

}
}
如何让以上的4个标签循环闪烁;最好带注释。
展开
 我来答
cxzucc
2011-10-17 · TA获得超过1317个赞
知道小有建树答主
回答量:1735
采纳率:79%
帮助的人:582万
展开全部
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Biaoqian extends JFrame
{
private JLabel b1;

private JLabel b2;

private JLabel b3;

private JLabel b4;

private JLabel[] labelArr;

public Biaoqian()
{
super("窗口");
setBounds(100, 100, 200, 200);
b1 = new JLabel("标签1");
b2 = new JLabel("标签2");
b3 = new JLabel("标签3");
b4 = new JLabel("标签4");
setLayout(new FlowLayout());
add(b1);
add(b2);
add(b3);
add(b4);
labelArr = new JLabel[] {b1, b2, b3, b4};
setLayout(new GridLayout(2, 1));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}

public static void main(String[] args)
{
Biaoqian biaoqian = new Biaoqian();
biaoqian.shanShuo();
}

public void shanShuo()
{
while (true)
{
for (int i = 0; i < 4; i++)
{
labelArr[i].setVisible(false);
try
{
Thread.sleep(1000);
}
catch (Exception e)
{
// TODO: handle exception
}
labelArr[i].setVisible(true);
}
}
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式