日期:2014-05-20  浏览次数:20886 次

求教java程序运行时print方法的调用问题?
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class Yard extends Frame {

private static final int ROWS = 50;
private static final int COLS = 50;
private static final int BLOCK_SIZE = 10;

public void lanuch() {
this.setLocation(200, 200);
this.setSize(COLS * BLOCK_SIZE, ROWS * BLOCK_SIZE);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}});
this.setVisible(true);
}

public void print(Graphics g) {
Color c = g.getColor();
g.setColor(Color.GRAY);
g.fillRect(0, 0, COLS * BLOCK_SIZE, ROWS * BLOCK_SIZE);
g.setColor(c);
}

public static void main(String[] args) {
new Yard().lanuch();
}
}


public void print(Graphics g)在运行时不是可以自动调用吗?为什么这个没有被调用,显示不出效果?

------解决方案--------------------
是不是paint()? 不是print()?