I have implemented the DDA algorithm to draw a line in Canvas. This is the listener for drawing the line:
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();
}
});
It works perfectly but everytime I draw another line, the first line dissappear because of the clear()
method. I need to keep the start and end points in a list so I could redraw the line after clearing. However I don't know exactly how to do that. How to keep the 4 points in a list?