08/04/14 13:04:35
間隔を置いて1文字ずつを流したいのですが、何十秒間表示なしで、突然いっきに文字列が出ます。
どうしたらいいんでしょう。ソースはこれです。
public void paint(Graphics g) {
Font font = new Font(null, Font.PLAIN, 30);
g.setFont(font);
FontMetrics metrics = g.getFontMetrics(font);
String text = "Get down on your knees. Beg for your life!";
int margin = 30;
int cx = margin, cy = 100, mx = getWidth() - margin;
for(int i = 0; i < text.length(); i++) {
g.drawString(String.valueOf(text.charAt(i)), cx, cy);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
System.out.println(e);
}
cx += metrics.charWidth(text.charAt(i));
if (cx > mx) {
cx = margin;
cy += metrics.getHeight();