qualcuno riesce a spiegarmi in modo semplice come funziona questa classe?
codice:
public class Whiteboard extends JPanel {
private String wb_name;
private Point start;
private Point stop;
private UserSession usersession;
private Shape shape;
private String stroke;
private Path2D path = new Path2D.Double();
public Whiteboard(String name, UserSession usersession) {
wb_name = name;
this.usersession = usersession;
setBackground(Color.white);
PathListener listener = new PathListener();
addMouseListener(listener);
addMouseMotionListener(listener);
this.setVisible(true);
}
public void paintComponent(Graphics gc) {
super.paintComponent(gc);
Graphics2D g2 = (Graphics2D) gc;
if (start != null && stop != null) {
BasicStroke stroke = new BasicStroke(1);
Shape strokedShape = stroke.createStrokedShape(shape);
g2.draw(strokedShape);
g2.fill(strokedShape);
}
}
public String getName() {
return wb_name;
}
public void setName(String name) {
wb_name = name;
}
private class PathListener extends MouseAdapter {
public void mousePressed(MouseEvent event) {
start = event.getPoint();
shape = path;
}
public void mouseDragged(MouseEvent event) {
stop = event.getPoint();
path = (Path2D) shape;
path.moveTo(start.x, start.y);
path.lineTo(stop.x, stop.y);
shape = path;
start = stop;
repaint();
}
public void mouseReleased(MouseEvent event) {
path = (Path2D) shape;
try {
path.closePath();
} catch (Exception ingore) {
}
shape = path;
repaint();
}
}
}