我有覆盖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);
}
答案 0 :(得分:0)
你压倒了错误的方法。摆脱" s"在方法名称的末尾。您需要覆盖paintComponent(...)
。
但是,您还需要覆盖paintComponent(...)
的{{1}}方法,您只需将该方法添加到您的课程中并期望它可以正常工作。这是Java 101。