I have a House class where I constructed a house by drawing java graphics (rectangle and lines). I have a SelectAndDragTest class which is the main class. When I run this class, it will generate a house on the JPanel. It is draggable. But when I click the button to add another house, I am able to drag the newly added house but not the previous houses. How do I make that other house is selectable upon mousepressed and draggable? I'd appreciate if anyone could give any suggestion. Below are my codes:
A painting method is for painting only. It should NOT create new objects.
Instead you need to modify your House class to have a "contains(Point mousePoint)" method.
The code might be something like:
In your mouseDragged() code you now need to iterate through all the Houses in the ArrayList and invoke the contains(...) method on each house. When you get a value of true you then need to adjust the x/y value of the house so it can be painted in its new location.