public class Show extends JFrame{
public Show(){
setTitle("Calcutor");
setSize(90*3,160*3);
setVisible(true);
}
}
public class Main {
public static void main(String args[]){
Show show=new Show();
Graphics g= show.getGraphics();
g.setColor(Color.pink);
g.fillRect(0, 0, show.getWidth(), show.getHeight());
}
}
上面这个不能显示图片。
public class Main {
public static void main(String args[]){
Show show=new Show();
Graphics g= show.getGraphics();
try
{
Thread.currentThread().sleep(1000);//毫秒
}
catch(Exception e){}
g.setColor(Color.pink);
g.fillRect(0, 0, show.getWidth(), show.getHeight());
}
}
当我加上
try
{
Thread.currentThread().sleep(1000);//毫秒
}
catch(Exception e){};
时就会显示图像,这是怎么回事?能不能 不加这个也能显示图像呢?