为什么延迟的字符串计时器不起作用?

时间:2015-03-17 02:20:52

标签: java swing timer

所以我有一个字符串计时器

import javax.swing.Timer;
import java.awt.event.*;

public class Delay implements ActionListener
{
    public void delay(int time)
    {
        Timer t = new Timer(500, this);
        t.start();
    }
    @Override
    public void actionPerformed(ActionEvent e)
    {
    }
}

延迟500毫秒(没有执行任何操作),但是,当我调用它时

Delay d = new Delay();
        for(char c : dialogue.toCharArray()){
            g2.drawString(String.valueOf(c),x,y);
            d.delay(5000);                               //here is the delay
            x += 10;
            if (x > 90){                                                                               
                x = 75;                                                                                         
                y = y + 20;                                                                            
            }
        }

写信之间没有延迟。为什么是这样? 谢谢!

0 个答案:

没有答案