repaint()

WXPQD 2004-03-31 11:36:01
为什么我的JLabel的标题不会变,一直是 "1"
public class MainFrame extends JFrame implements Runnable
{
boolean flag;
int count;
MainFrame()
{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(new JLabel("1"));
this.setSize(100,100);
this.setVisible(true);
Thread t1=new Thread(this);
t1.start();
}
public void refresh()
{
this.getContentPane().add("label"+count++);
flag=false;
}
public void run()
{
while (true)
{
try
{
Thread.sleep(100);
}
catch (Exception e)
{
e.printStackTrace();
}
if (Manager.getFlag())
{
this.refresh();
}
}
}
}
class Manager extends Thread
{
boolean flag=false;
Manager(){start();}
public static boolean getFlag()
{
return flag;
}
public void run()
{
try
{
Thread.sleep(1200);
}
catch (Exception e)
{
e.printStackTrace();
}
flag=true;
}
}

...全文
64 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧