import javax.swing.*;
import java.awt.*;
public class Example extends JApplet{
public void paint(Graphics g){
int k;
Graphics2D g2=(Graphics2D)g;
this.setBounds(20,30,200,300);
Font f=new Font("SansSerif",Font.BOLD+Font.ITALIC,15);
g2.setFont(f);
g2.setColor(Color.red);
for(k=0; k<5; k++){
g2.drawString("k="+k,4*(k+1),20*(k+1));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
g2.drawString("The end of Applet Thread!",4*(k+1),20*(k+1));
}
}
[b]问题补充:[/b]
谢谢你的回答!
我运行的怎么是两遍呀 !!
是先输出:
k=0
k=1
k=2
k=3
k=4
然后刷新了,又输出:
k=0
k=1
k=2
k=3
k=4
The end of this dos thread
我试了一下,好像是this.setBounds(20,30,200,300); 导致的第二遍
不知道是为什么??