I'm trying to write an application in java that connects two jLabels on a panel by dragging a line from one to the other. I can create lines between two points on the panel OK but I can't figure out how to get the panel to recognise that when I hold the mouse down on the label I want to start drawing the line, and likewise that when I release the mouse on the target I want to stop drawing.
I draw the lines by overriding the panel's paintComponent method:
@Override
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
Enumeration e = stack.elements();
g2d.setPaint(Color.black);
while (e.hasMoreElements()) {
g2d.draw((Line2D) e.nextElement());
}
g2d.setPaint(blank);
g2d.draw(savedLine2d);
g2d.setPaint(Color.black);
g2d.draw(line2d);
}