Hi prof Hwang!
i been thinking and looking at the codes for the 2 bar magnet java applet. I am unable to remix applet faster now, due to my baby girl 3 month old!  ;D ;D need to pay more attention to family needs. BTW U can join facebook to see more photos of the baby! LOL http://www.facebook.com/lookang

i managed to get your codes to work in my own remix java applet at the top post.

i am stuck figuring out a clever way to make the getB values to saturate to the direction of the orientation of the bar magnet for both magnets. I have a version 04 that works for one magnet[img]http://www.phy.ntnu.edu.tw/ntnujava/index.php?action=dlattach;topic=1602.0;attach=2846;image[/img] but not both [img]http://www.phy.ntnu.edu.tw/ntnujava/index.php?action=dlattach;topic=1602.0;attach=2848;image[/img].

[color=blue]public double[] getB(double xm,double ym) {
double[] b=new double[2];
for(int i=0; i < nd; i + +) {
double dx=xm-dipoles[ i ][0];//-xm;////(xMagnet*cs+yMagnet*sc);//FKH
double dy=ym-dipoles[ i ][1];//-ym;//(-xMagnet*sc+yMagnet*cs);//FKH
double r2=dx*dx+dy*dy;
double r=Math.sqrt(r2);
double r3=r2*r;
double cos=dx/r;
double sin=dy/r;
b[0]+=m*(3*cos*cos-1)/r3;   //x component
b[1]+=m*3*sin*cos/r3;   //y component
if(r2==0) {
b[0]=b[1]=0;
}
}
//  b[2] = Math.sqrt(b[0]*b[0]+b[1]*b[1]);  // magnitude
//  b[3] = Math.atan2(b[1],b[0]);  // angle
return b;
}[/color]

This is my code changes (latest version which i still couldn't get it to work the way inside the magnet)
[color=red]//inside any magnet
if (xCompass<(xm+Magnetsizex/2) && xCompass>(xm-(Magnetsizex/2)) && yCompass<(ym+Magnetsizey/2) && yCompass>(ym-Magnetsizey/2))
{
test = true;
b[0] = (225)*vectorfieldmaxopposite/100; // saturate to direction of magnet Bx'=255 if vectorfieldmaxopposite=1
b[1] = (0)*vectorfieldmaxopposite/100; // saturate to direction of magnet By' =0

}

else // original code for field
{
test=false;
b[0]+=m*(3*cos*cos-1)/r3*vectorfieldmaxopposite/100; ;   //x component vectorfieldmaxopposite/100 is a factor i made
b[1]+=m*3*sin*cos/r3*vectorfieldmaxopposite/100; ; //y component
}[/color]

it is not working the way that i conceptualize it would work.
chance to look at it and make the codes work?
i think your teaching method is great, u do it on your applet and i study it. can help? ;D