Planet caps = new Orbit(moon,
Color.BLUE,2,10,0,0.08,
Color.BLUE);
... and change the line that creates the planets array to:
planets = new Planet[]{sun,earth,moon,caps,ufo};
More interestingly, what if we wanted to add some "Planet" with
decaying orbits?
Well, our Orbit class needs a bit more functionality to do that
nicely. We'd have to add
public double getOrbitRadius() { return orbitRadius; }
public void setOrbitRadius(double dr) { orbitRadius = dr; }
to Orbit.java. But with that in place, a decaying orbit class
is simply an extension of the Orbit class in which we override
the step() method to reduce the radius as well as change the angle.
Foo.jar, you can run the program
it contains with the command:
java -jar Foo.jarThe one thing that's not clear, however, is what class has the main() method that should start things off. After all, many .class files could contain main() methods. The way this is handled is that a file called
Manifest.txt is
bundled together with all the .class files in the jar file. And
Manifest.txt has a line that states which class has the main()
method that should be called to kick off the program.
Assuming we have the program L12 defined above, we would create
a jar file by first creating the file Manifest.txt:
| Manifest.txt |
Main-Class: L12 |
jar cfm SolarSystem.jar Manifest.txt *.classThis creates the file SolarSystem.jar that we can send off to other people, who can run it (on any platform with a JVM) with the command:
java -jar SolarSystem.jarSince the "compiled" code is byte-code compiled for the JVM, rather than true machine-code, it can be run anywhere ... provided the host platform supports the version of Java you compiled to.
For your viewing pleasure, I've included SolarSystemA.jar and SolarSystemC.jar for you to run. Note: beware of running .jar files when you're not absolutely sure that a) the person who wrote it is on the up and up, and b) that you're really gotten the file you think you have!