0

I'm using the method drawLine to draw lines in a JPanel. Is there a way to add an ActionListener, or something similar to the lines, so that clicking on the lines will pop out a JOptionPane?

Any other alternative to drawing lines that can suit my purpose?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 2
    What you’re describing is “hit detection”, you need to start with a MouseListener, then you need to be able to determine if the mouse point was clicked on line, which probably means you need to maintain some kind of Museo ehh but represents all the lines that have been drawn – MadProgrammer May 21 '18 at 22:27
  • I will try to use this kind of approach. I already have an arraylist of all the lines, as I use that to draw the lines in the paintComponent method – Michele Fattoruso May 24 '18 at 21:27

0 Answers0