Solved

Random image move

Posted on 1998-07-14
4
190 Views
Last Modified: 2010-03-30
In my applet i want to randomly generate and move the images. I also
want to store current positions of all the images moving around. it should
move in upwards directions and in a particulare region. Please help
me out with the code.
0
Comment
Question by:hateli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Expert Comment

by:HoJu
ID: 1226048
Hateli, could you state the question more clearly? In particular, I'm wondering:

- What kind of images are you generating?
- How often do you want to generate and move them? Every second? In response to a mouse click or keypress?
- What do you mean by "It should move in upwards directions and in a particular region"?
0
 

Author Comment

by:hateli
ID: 1226049
Hi hoju ,

I have one image of of balloon.gif. i want to randomly
move the ballons from down to up . my applet is of 500,
300 size. now balloons should be randomly flying only in
area of right hand corner of applet that is say 200 pixels
from right corner. it should start as soon as applet
gets started. if i press a space bar stone flys from
down to up and if it hits a ballon i get 100 pts.

I hope thsi is clear to you

Anticipating a reply

0
 
LVL 2

Accepted Solution

by:
shchuka earned 100 total points
ID: 1226050
Sounds like you need a separate thread for drawing the balloon.
Here's what you can try to do.

1. Create a class called Balloon, which extends Canvas and in its paint() method draws the ballon.gif in itself.

2. Create a class called BalloonMove, which extends Thread.  This one should have
variables x and y for current location and an object of type Balloon.

3. Provide a mechanism to specify to an object of the class BalloonMove where to draw the balloon (e.g. put a method in it, which would accept Applet a as a parameter and store it in some private object variable)

4. In BalloonMove.start() method, add the balloon object to the applet and initialize the initial coordinates x and y to something using Math.random() for x and applet's height
for y.

5. In BalloonMove.run() method, decrement the y coordinate by whatever you want the balloon to move, then use setLocation() method of the ballon object to set the new location of the balloon.

6. Add a method getCoordinates() to the BallonMove class, which would return, for example, a Point object with the current x and y coordinates.

7. In the applet's start method(), put the code to create an object of type BalloonMove, tell it what the applet is (see 3), and start it.  In the applet's run() method, you can use BalloonMove's method getCoordinates() to determine the current position of the balloon.  Do not forget to stop the BalloonMove thread in the applet's stop() method.

Good luck.
0
 

Author Comment

by:hateli
ID: 1226051
Please could U pass on the code ! it would be very much halpful
Thankx a lot
Anticipating a Reply ASAP
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question