Hi there shaz_600. I've since had a closer look at the Elements
package, and it certainly seems to be the right one - so I've gone
ahead and finished the code for you. It's available from:
http://xult.org/shaz_600/MainWindow.java
http://xult.org/shaz_600/Animation.java
http://xult.org/shaz_600/ScreenSetup.java
Additionally, you may see a screenshot of the animation below. It
features a house, with a chimney blowing smoke. A FedEx truck races up
to the house, and every 75 frames the animation restarts.
http://xult.org/shaz_600/anim.gif
Let me give you a short overview of how the code works. If you feel
that you need more information, please feel free to ask. The code
assumes that the Elements classes are stored in the normal place, and
uses the statement:
import element.*
to import these. If your system stores these classes elsewhere, you
may need to change that line in each of the files I provided.
There are three classes:
MainWindow: This class merely sets up a DrawingWindow and passes it to
the Animation class. You must run this class to start the program (the
command "java MainWindow" should suffice, once all classes are
compiled).
Animation: This class runs as a thread, and performs most of the hard
work in the animation. It draws all of the moving items on the screen,
and works out where they should be placed each frame.
ScreenSetup: This class draws all the basic things which never need to
be changed. For instance, the sun, the grass, and the sky.
The code is well organized and fully commented, so it should be fairly
easy for you to work on and understand. If, however, you need further
assistance or help in understanding it, then please do not hesitate to
use the request clarification feature before rating this answer.
Thanks for an interesting challenge, and good luck with your course.
--seizer-ga
PS - If this is a school assignment, you may be interested to know
that Google has a specific category for getting help with these. It's
located at:
Google Answers > Reference, Education and News > Homework Help
If in the future you have more questions for us which are school
related, I'd advise you to post your question(s) there to receive more
appropriate attention. Thanks! |
Clarification of Answer by
seizer-ga
on
27 Nov 2002 14:27 PST
Hello there shaz_600. I'm glad you're pleased with the work.
It certainly should work on your computer. What you'll need to do is
to examine any previous exercises or assignments which used the Bailey
and Bailey Java Elements, and check for a line at the top of the code
which says something like:
import element.*;
If it's different in these files, then just include that alternative
line in the code I have given you, and it should compile well. I can't
really help you more on this one until you try it on your work
computer. Make sure that you have the latest version of the Java
Elements, from:
http://www.cs.williams.edu/~bailey/JavaElements/
As for threads, there's a lot that could be said - if you wanted a
really in depth breakdown, you could even post a new question: it's a
very interesting topic. The most simple description, is that a thread
lets you run part of a program on its own, while letting other bits
run at the same time: simultaneous execution. It's a bit like
multitasking. I used it in your program because it was the best way to
get the animation working. They're extremely simple to do in Java -
just make sure the class "implements Runnable", and make sure it has a
run() method. You can see this in the Animation class.
For more thread information, see here:
http://java.sun.com/docs/books/tutorial/essential/threads/
As for the classes themselves, I believe they're fairly self
explanatory. All you need to do is run the MainWindow class. If you
open each of them up in your editor, and read through the comment
lines, you'll be able to see that they're fairly well described. If
there's a specific detail that you're unclear on, though - please ask!
Good luck,
--seizer-ga
|