Use a graphics program of your choice to draw the magnet animation (good programs surely will give you a tutorial how to do animations). Then you can use, e.g., Java Swing to display it (see http://java.sun.com/docs/books/tutorial/ui/features/index.html for more help).
Or see CeciNEstPasUnProgrammeur answer below. :)
Message was edited by: stefan.schulz
Something like this?import java.util.Random;
public class Magnet {
private static final String[] mmm= {
"What's a girl like you doing in a place like this?",
"Come closer cutie",
"Hmmmmm ...",
"What's keeping you?",
"Waiting for Mister GoodBar?",
"I can't wait any longer",
"Here's daddy!"
};
private static final String[] eeeww= {
"Eeew! Get your nose out of there!",
"*Boink!*",
"*Clunk!*",
"You pervert!",
"Huh?!",
"You're into *what*?",
"Waidaminnit now!"
};
private static Random r= new Random(System.currentTimeMillis());
private static void m(String[] m) { System.out.println(m[r.nextInt(m.length)]); }
private void attract(Magnet other) {
m(mmm);
other.attract(this);
}
public static void main(String[] args) {
Magnet north= new Magnet();
Magnet south= new Magnet();
try {
north.attract(south);
}
catch (Error e) {
System.out.println();
m(eeeww);
}
}
}
kind regards,
Jos ;-)
> Hi,
>
> Is there anyone who knows how I can do the java
> programming for a magnet?
>
> thanks!
I'm not sure what's your problem! Are you familiar with the physics involved (Maxwell laws, electric fields, magnetic fields...) and want to "translate" them to java code or you just want to make an animation?
Manuel Leiria