This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Please help!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Please help!!!!" Watch "Please help!!!!" New topic

Please help!!!!

Stephen Norris
Ranch Hand

Joined: Oct 27, 2003
Posts: 44
I am writing a program that is suppose to show a moon lander image going up and down on a JPanel. I don't know what I am doing and have barely got anything down. Below is what I have so far. Can someone please help me at least get started on this. I am a beginning student and I am lost. I am in jeopardy of failing my class if I don't do this. I am not asking anyone to write the program for me, but I don't even know where to start.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

In the while loop, call Thread.sleep() to pause for 50 ms or so, then increment an integer member variable, then call repaint(). Now, override paintComponent() to draw the lunar lander at a certain position (you might use Graphics.drawImage() to render a JPG file.) Calculate the position based on the same member variable; the "while" loop will this make the lander move.

[Jess in Action][AskingGoodQuestions]
Stephen Norris
Ranch Hand

Joined: Oct 27, 2003
Posts: 44
I don't get what I am doing, but thank you for trying. This does not make much sense. I get the concept of the project, I just can't actualize the whole thing and I don't know what I am doing or where to begin. Thanks again.
Ben Wood
Ranch Hand

Joined: Aug 14, 2001
Posts: 342
Hi Stephen,
The class you have extends JPanel. The JPanel class defines a method called PaintComponent which tells it how to draw itself on screen. If you override this method in your own class you can tell the JPanel how to draw this case you will draw an image at a particular location, so you need a method like...

The image_object is an Image object that you have loaded in from, say, a JPEG picture. The width and height are the dimensions of the image. The x and y will define where to put the top left corner of the picture (I think top left anyway ). If you define the x and y variables earlier in the class and then use the while loop something like this....

maybe this helps a little? You will need some extra logic to make the lander image move up and down...the code above will just cause it to keep moving up the JPanel.
In the main class that uses the JPanel (e.g. a class extending JFrame), add the ImagePanel object to the layout and then call startAnimation().
[ March 22, 2004: Message edited by: Ben Wood ]

SCJP 1.4,
I agree. Here's the link:
subject: Please help!!!!
It's not a secret anymore!