苦恼的graphics问题!

gutianya 2002-03-04 08:21:15
以前提到过这个问题,好象是解决了,可是昨天用起来,好象还是老样子!
Class pane extends JPanel{
public void pane()
{
Graphics g=getGraphics();//←---为什么编译能通过,而执行时会出现
} //↓--- 空指针问题!!!
}
曾有老鸟说过getGraphics()只有用在当前对象中才不会出现类似问题,我也试过
为体依然没有解决
再次高手!
...全文
43 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
gutianya 2002-03-06
  • 打赏
  • 举报
回复
多谢回复,不过不是classpath没有设好,我们公司的其它程序运行正常,也不是没有导入javax.swing.*,如果这样,根本就不能通过编译!至于Joelay(磊子) 所说,我前面已经说过了,即使是当前对象也不行!
wolfsquare 2002-03-05
  • 打赏
  • 举报
回复
将完整代码贴出来。
Eric_yu 2002-03-04
  • 打赏
  • 举报
回复
你的语法及用法都没有错,可能是你的classpath没有设好。或者没有导入
javax.swimg.*
Joelay 2002-03-04
  • 打赏
  • 举报
回复
public Graphics getGraphics()Creates a graphics context for this component. This method will return null if this component is currently not displayable.

Returns:
a graphics context for this component, or null if it has none
Since:
JDK1.0
See Also:
paint(java.awt.Graphics)

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧