0

我正在尝试制作一个相当简单的小程序 - 单击鼠标后,我们会使用新字符串重新绘制。这本质上是一个倒计时(3,2,1...退出)。但是,在睡眠循环结束之前,小程序似乎不想重新绘制。见代码:

        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++;
    }

我怀疑这是覆盖绘制事件的鼠标事件?我很困惑

4

0 回答 0