Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where to Start???

Status
Not open for further replies.

PADFOR

Programmer
Feb 5, 2001
25
GB
I have been trying to solve the following problem from a java book, and I have no joy. Could you someone please give me some pointers?

The Task

Your task is to write a Java application which allows us to animate several simple shapes within a defined area of the application (perhaps a Panel). Shapes should
"bounce" off the boundary of this area. The application should be multithreaded, where appropriate. You may impose an upper limit on the number of shapes if you
wish, but should allow at least up to 10 shapes.


Requirements

Your application should:

1.Allow the user to add simple shapes (circles and squares) into the animation area.
2.The user should be allowed to specify:
a.which shape to add,
b.the size of the shape,
c.which colour to fill the shape with,
d.the initial trajectory (dx and dy) values.
3.Shapes should not collide with each other but should pass "through" or "over" each other.
4.Allow the user to stop/start one of the shapes moving by clicking it. The motion of all the other shapes should be unaffected by this.
5.Whilst a shape is stopped the user should be able to change the size, shape, colour and trajectory of the shape (e.g. via a dialog box which pops up when the
shape is clicked). You should not allow the attributes of a shape to be changed whilst it is in motion.
6.Allow the user to stop/start all of the shapes by clicking in the background of the animation area.
7.Use off screen images and clipping areas to make the animation smooth
 
Sounds like you need a bit more than Just Java programming! There's a really good book 'Graphic Java 1.2' which details most of what you need to know.

Regards
 
I would start by studying the theory of OOP (Object Oriented Programming). Those technics will help you treat your shapes as objects and allow you to Encapsulate the data with your methods. It will also save on some coding because you can use Inheritence from a shape superclass. Lastly, make your shape class abstract or an interface. This way you can take avantage of Polymorphism. Basically, you can have an array of references which refer to each shape. Then you can loop through your array and call one method draw to paint each shape on the screen. The JVM will automatically know how to draw each shape because you override the method in each concrete shape class. The JVM determines this by what type of object was instantiated for that reference.

You have a lot of work ahead of you to do this project. I would break it down and do little pieces at a time. That is one good thing with Java, is it promotes code-reuse and class object modules.

Consider taking a Java programming class with emaphsis on OOP. It will make this project a lot easier. This is more advanced and if I gave this to my students it would take most of them the whole semester to put it together.

Good luck,
Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top