线程休眠后重新编写Java applet

时间:2013-07-03 14:33:20

标签: java applet awt mouseclick-event

我想要制作一个相当简单的小程序 - 一旦点击了鼠标,我们就会重新编写一个新的字符串。这基本上是一个倒计时(3,2,1 ...退出)。但是,在睡眠循环结束之后,applet似乎不想重新绘制。见代码:

        public void paint(Graphics g){
      g.setColor(Color.blue);
      g.stringtoprint(s1,300,150);

      }



public void mouseClicked(MouseEvent mev) {
    mouseClicked = true;
    int j = 0;

    while(j<=3){

        if (j < 3)
        {
        stringtoprint = "Self destruct in: " + (3-j);
        try{Thread.sleep(1000);

        }
        catch(InterruptedException e){}
        finally{            

        System.out.println("click!");} -- this line works in the console
        this.repaint(); --doesn't repaint until countdown is over(and then exits)
        }
        else {System.exit(0);} --exits applet when j=3
        j++;
    }

我怀疑这与mouseevent一起覆盖了paint事件?我很困惑

0 个答案:

没有答案