为何用“一”不能画出圆,而用“二”却能画出圆呢?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Draw extends Frame{
//一
public void print(Graphics g) {
super.print(g);
Color c=g.getColor();
g.setColor(Color.RED);
g.fillOval(100, 100, 40, 40);
g.setColor(c);
}
//二
// public void paint(Graphics g){
// Color c=g.getColor();
// g.setColor(Color.RED);
// g.fillOval(100, 100, 30, 30);
// g.setColor(c);
// }
public void lauchFrame(){
setSize(800,600);
setResizable(false);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
setBackground(Color.GREEN);
setVisible(true);
}
public static void main(String[] args) {
Draw d=new Draw();
d.lauchFrame();
}
}
------解决方案--------------------
paint()会被自动调用 print()不会