How can I paint continous line in JPanal made by rectengle.
My Code:
@Override
public void mousePressed(MouseEvent e) {
x = e.getX();
y = e.getY();
points.add(new Point(x, y));
repaint();
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, this.getWidth(), this.getHeight());
g2d.setColor(Color.BLACK);
drawRectangles(g2d);
drawLines(g2d);
}
points is a List to store my rectengle.
I want to draw continous line on pressed button, but all I've got is one rectengle per click.
private void drawRectangles(Graphics2D g2d) {
int x, y;
for (Point p : points) {
x = (int) p.getX();
y = (int) p.getY();
g2d.fillRect(x, y, 10, 10);
}
}