我有一个在开始时绘制点的 JPanel。当我在这些点之间遍历时,我试图在这些点之间添加线。但是线条没有出现。如果我使用重绘,以前的绘图就会消失。下面是我的代码。我是否需要刷新 drawLine 代码中的某些内容?
public void paintComponent(Graphics g) {
super.paintComponent(g);
doDrawing(g);
}
//works fine
private void doDrawing(Graphics g) {
g.drawLine(x, y, x, y);
}
//called later from outside, lines do not show up on Panel
public void drwaLine(Point p1, Point p2) {
Graphics g2d = getGraphics();
g2d.drawLine(p1.getX(), p1.getY(), p2.getX(), p2.getY());
}