java图形界面,为什么延迟时间没有起作用,还是所有的一起都同时显示出来?
importjavax.swing.*;importjava.awt.*;publicclassDrawOnJPanelextendsJPanel{publicstati...
import javax.swing.*;
import java.awt.*;
public class DrawOnJPanel extends JPanel{
public static void main(String[] args){
JFrame f=new JFrame("绘制图形");
DrawOnJPanel d=new DrawOnJPanel();
f.getContentPane().add(d);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(300,200);
f.setVisible(true);
}
protected void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(Color.red);
g.drawString("字符串",20,50);
try{
Thread.sleep(1000);
}
catch(Exception ex){}
g.drawLine(120,10,200,50);
try{
Thread.sleep(1000);
}
catch(Exception ex){}
g.drawRect(60,80,getWidth()/2-30,getHeight()/2-30);
g.drawOval(60,80,getWidth()/2-30,getHeight()/2-30);
}
} 展开
import java.awt.*;
public class DrawOnJPanel extends JPanel{
public static void main(String[] args){
JFrame f=new JFrame("绘制图形");
DrawOnJPanel d=new DrawOnJPanel();
f.getContentPane().add(d);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(300,200);
f.setVisible(true);
}
protected void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(Color.red);
g.drawString("字符串",20,50);
try{
Thread.sleep(1000);
}
catch(Exception ex){}
g.drawLine(120,10,200,50);
try{
Thread.sleep(1000);
}
catch(Exception ex){}
g.drawRect(60,80,getWidth()/2-30,getHeight()/2-30);
g.drawOval(60,80,getWidth()/2-30,getHeight()/2-30);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询