paint内にThead.sleepがダメいうことで、classをつくって、その中でsleepを定義してオブジェクトを作り、それをpaint内で呼び出して使おうとしましたが、うまくいきません。、Thread.sleepをどう使えばいいですか? public class SleepT { public void sleepii(){ try { Thread.sleep(500); } catch (InterruptedException e) { System.out.println(e); } } SleepT s = new SleepT();
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); s.sleepii(); cx += metrics.charWidth(text.charAt(i)); if (cx > mx) { cx = margin; cy += metrics.getHeight(); } }