当前位置: 代码迷 >> J2SE >> 求教java程序运行时print方法的调用有关问题
  详细解决方案

求教java程序运行时print方法的调用有关问题

热度:9742   发布时间:2013-02-25 00:00:00.0
求教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()?
  相关解决方案