I download your code and modified it.
I remove drag action in [u]objectblue[/u], disable [u]objectnewdesign[/u] and add [u]objectnewdesignFKH[/u].
[code]
oxmax=oxmin+x;
if(w>x){
  if(oy>oymin-h/2)oy=oymin-h/2;
  outobject=true;
}else{// object is smaller than the width
if(outobject){// if object is outside do the following check
  if(ox-w/2>oxmin && ox+w/2<oxmax && oy+h/2>oymin){// move inside
    outobject=false;
  }else{
    if(ox-w/2<oxmin || ox+w/2>oxmax){
      if(oy+h/2>oymin)oy=oymin-h/2;
    }
  }
}else{// if object is inside do the following check
  if(oy+h/2<oymin)outobject=true;// move outside again
  else{
  if(oy+h/2>oymax)oy=oymax-h/2;
  if(ox-w/2<oxmin)ox=oxmin+w/2;
  else if(ox+w/2>oxmax)ox=oxmax-w/2;
  }

}
[/code]

The result is the following

/htdocs/ntnujava/ejsuser/2/users/ntnu/fkh/LookangVernierCaliper04FKH_pkg/LookangVernierCaliper04FKH.propertiesFull screen applet or Problem viewing java?Add http://www.phy.ntnu.edu.tw/ to exception site list
Press the Alt key and the left mouse button to drag the applet off the browser and onto the desktop. This work is licensed under a Creative Commons Attribution 2.5 Taiwan License
Download EJS jar file(845.5kB):double click downloaded file to run it. , Download EJS source (5 times by 3 users) View EJS source