This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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.
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.
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 itself...in 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 ]