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个标签循环闪烁;最好带注释。 展开
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个标签循环闪烁;最好带注释。 展开
1个回答
展开全部
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);
}
}
}
}
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);
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询