Thanks prof hwang, ur ideas helped give me the tools to experiment with the codes until i got this. I must thank you for your support even on Saturday  and Sunday because u made a difference in my learning!
this web2.0 forum is super cool, better than email because everyone else can learn, emails get lost in cyberspace after some time.

The codes seems to work reasonable well most of the times for blue object on drag

// use 2000 instead of 0 for realistic boundary detection
if (( ox-w/2-oxmin)*(ox+w/2-oxmax) > 2000 &&  (oy+h/2-oymin)*(oy+h/2-oymax) < 0 && outobject == true){ // "detect bottom codes" suggestion by wolfgang method by hwang to detect outside the jaws

oy = oymin-h/2; // force blue object to be fixed just below jaw
}

if (x < w && outobject == true && (oy+h/2-oymin) > 0){ // jaw too narrow for object

oy = oymin-h/2; // force blue object to be fixed just below jaw
}

// use 2000 instead  of 0 for overcoming the blue object at the very top
if ((ox-w/2-oxmin)*(ox+w/2-oxmax) <= 5000 && oy+h/2 - oymin >= 0 && outobject==false){ // "inside codes"  detect inside jaws
 if ( (ox-w/2-oxmin)<= 0) // if exceed into the left jaw
{
   ox=oxmin+w/2; // force blue object to sit by the side of left jaw
 }
 if ((ox+w/2-oxmax) >= 0) // if exceed into the right jaw
 {
   ox=oxmax-w/2; // force blue object to sit by the side of right jaw
   }
   }

http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=684. has the  new blue object codes, check it out ;)