【发布时间】:2018-02-02 15:49:23
【问题描述】:
我已经覆盖paintComponents 方法,但是当我使用它并运行我的程序时,它不会显示任何圆圈和线条。最近frakcool说不是paintComponents方法,是paintComponent方法。我发现了,但我没有得到任何paintComponent 方法。
这张图表明我没有任何paintComponent方法:
代码在这里。
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
SecondActivity frame = new SecondActivity();
frame.setBackground(Color.WHITE);
frame.paintComponents(null);
// frame.paint(null);
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
@Override
public void paintComponents(Graphics g) {
// TODO Auto-generated method stub
super.paintComponents(g);
Graphics2D g2d = (Graphics2D) g;
drawCircle(g2d,centerX,centerY,r);
drawLineAzim(g2d);
drawLineEle(g2d);
}
【问题讨论】:
-
正如我在this comment 中所说并在我对您其他问题的回答中显示的那样,您需要覆盖
paintComponent()而不是paintComponentS()。该方法属于JPanel,这就是我扩展它的原因。 -
(1-)
recently frakcool said it is not paintComponents method, it is paintComponent method.- 那你为什么还在执行错误的方法???您甚至使用paintComponent(...)方法在论坛中搜索其他示例??? -
如需更好的帮助,请尽快(重新)阅读minimal reproducible example 指南
-
但是我无法获取paintComponent方法,请帮助。我应该去哪里找呢?
标签: java swing jpanel paintcomponent