protected Graphics()构造一个新的 Graphics 对象。此构造方法是用于图形上下文的默认构造方法。
因为 Graphics 是一个抽象类,所以应用程序不能直接调用此构造方法。图形上下文从其他图形上下文获取,或者通过在组件上调用 getGraphics 来创建。
public static void main(String[] args) throws Exception {
TestA a=new TestA();
a.paint(a.getGraphics());
}
main函数这么写就可以了 不过会空指针,因为没有Graphics对象
必须用小程序的方式执行 paint不用传参数