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

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -