我正在开发小程序,我的类扩展了一个第三方 api 类,它有它的paint(Graphics g) 方法。此类扩展 JComponent 并从它的paint(Graphics g) 中调用 super.paint(g)。现在我想从我的类中直接调用 JComponent 绘制方法。有没有办法做到这一点。我在下面尝试但给出错误
getParent().getParent().paint(g);
或者您可以通过以下方式理解这一点
ThirdPartyClass 扩展 JComponent{
公共无效油漆(图形g){
super.paint(g);
//一些工作
}
}
MyClass 扩展 ThirdPartyClass{
公共无效油漆(图形g){
getParent().getParent().paint(g); // 不工作给出异常
}
}
