我想在runnable中绘制一个字符串,然后几秒钟后,在该字符串中添加另一个单词,然后重复。 runnable有效,但它不会被drawString?
如果有人需要编译并试用它,我已经制作了一个只有我想要的迷你应用程序。
这是:
package timer.problem.example;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JFrame;
public class TimerProblemExample extends JFrame {
private static final long serialVersionUID = 1L;
public TimerProblemExample() {
setBackground(Color.black);
setVisible(true);
setTitle("Timer Problem Example");
setSize(950, 600);
setDefaultCloseOperation(3);
}
public static void main(String[] args) {
new TimerProblemExample();
}
public void timer(final Graphics graphics) {
new Timer().schedule(new TimerTask() {
int update = 6;
public void run() {
update--;
graphics.setFont(new Font("Splash", Font.PLAIN, 60));
graphics.setColor(Color.white);
if (update == 5) {
graphics.drawString("Test", 50, 130);
repaint();
}
if (update == 3) {
graphics.drawString("Test Test", 50, 100);
repaint();
}
if (update == 1) {
graphics.drawString("Test Test Test", 50, 50);
repaint();
}
}
}, 0L, 1000L);
}
@Override
public void paint(Graphics graphics) {
super.paint(graphics);
timer(graphics);
}
}
请帮助,谢谢。
答案 0 :(得分:0)