Java, If a draggable object touches other object -


i have code dragging label width mouse.

lbl_banner.addmouselistener(new mouseadapter() {     @override     public void mousepressed(mouseevent e) {         //catching current values x,y coordinates on screen         x_pressed = e.getx();         y_pressed = e.gety();     } });  lbl_banner.addmousemotionlistener(new mousemotionadapter(){     @override     public void mousedragged(mouseevent e){         //and when jlabel dragged         setlocation(e.getxonscreen() - x_pressed, e.getyonscreen() - y_pressed);     } }); 

now, how make function: while i'm dragging label around screen, if label dragging touches other object (label, button,...) something.

if(//labeltouchessomething){//do something} 

while not technically dragging dynamic move of component (dragging transfer of contents in between components), can compute intersection of current moving component against other components (this may need navigation inside hierarchy). may can you: how detect collison of components?. can use methods contains of component determine if coordinates inside component or not.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -