清除画布后如何重绘线条

时间:2017-10-31 09:06:42

标签: java canvas

我已经实现了DDA算法在Canvas中绘制一条线。这是绘制线的听众:

panel.addMouseMotionListener(new MouseAdapter() {
        @Override
        public void mouseDragged(MouseEvent e) {
            final double startX = previousX / (panel.getWidth() - 1.0); //k zamysleni: proc 1.0 a ne 1?
            final double startY = 1 - previousY / (panel.getHeight() - 1.0);
            final double endX = e.getX() / (panel.getWidth() - 1.0);
            final double endY = 1 - e.getY() / (panel.getHeight() - 1.0);
            clear(); // zkuste zakomentovat
            rasterImage = liner.rasterizeLine(rasterImage,
                    startX, startY, endX, endY,
                    0xffff00);
            panel.repaint();
        }
    });

它完美无缺,但每次我绘制另一条线时,第一行因clear()方法而消失。我需要在列表中保留起点和终点,这样我就可以在清除后重新绘制线条。但是,我不确切知道如何做到这一点。如何将4个点保持在列表中?

0 个答案:

没有答案