为什么main_frame.getGraphics()返回的值是null呢??? -----你从哪里看出结果是null?
但当我在Main_Frame类下用this.getGraphics()这样获得的值就是正常的...
------你从哪里看出结果的正常的?这些应该说清楚。
但当我在Main_Frame类下用this.getGraphics()这样获得的值就是正常的...
------你从哪里看出结果的正常的?这些应该说清楚。
这跟调用的位置有关
只有graphic需要的frame属性都设置完了,才能生成graphic
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("测试");
System.out.println(frame.getGraphics());
}
这是输出是null如果:
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("测试"); JPanel panel = new JPanel();
frame.setContentPane(panel);
panel.setLayout(new FlowLayout());
frame.setSize(300, 200);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width - frame.getSize().width) / 2,
(d.height - frame.getSize().height) / 2);
frame.setVisible(true);
System.out.println(frame.getGraphics()); }这个时候,输出是:
sun.java2d.SunGraphics2D[font=java.awt.Font[family=Dialog,name=Dialog,style=plain,size=12],color=java.awt.Color[r=0,g=0,b=0]]
frame.getGraphics()返回的就不会是空了
if (Main_Application.frame!=null){//假如主界面没抽取过
Main_Application.frame.update(Main_Application.frame.getGraphics()); //当点了按钮后,更新所有的FRAME界面
while (true) {
i++;
//Thread.currentThread().sleep(100);
System.out.println("第" + i + "条记录成功抽取!!\n");
Main_Application.frame.jTextInfoArea.setText("第" + i +
"条记录成功抽取!!\n");
Main_Application.frame.jTextInfoArea.update(Main_Application.
frame.jTextInfoArea.getGraphics()); //更新监控的文本框界面
}
}
但是执行到1500次的时候就报错了错误如下:
java.lang.InternalError: getGraphics implemented only for Canvas Components at sun.awt.windows.WGraphics.createFromGraphics(Native Method)