Solved

Random Images

Posted on 1998-07-18
4
207 Views
Last Modified: 2010-03-30
I want to randomly generate and move image of ball  from down to up .
i also want to store every x and y co ordinates of each ball untill it is vanished from top.
0
Comment
Question by:yeda
4 Comments
 

Accepted Solution

by:
tomd012698 earned 50 total points
ID: 1226994
This is the basic plan.  You'll need to fill in some of the gaps, but I think this will help.

1) Create a class that represents the location, and and motion of the ball.
2) Create a Vector within your Applet class to store the balls.
3) Create an animator thread to periodically update the location.

class Ball
{
  public Image _image = null;
  public int _x;
  public int _y;
  public int _xDelta;
  public int _yDelta;
}

class BallApplet extends Applet
  implements Runnable
{
  private Vector _vector = new Vector();
  private Thread _thread = new Thread( this );
  private Image _ballImage = null;

  public void start()
  {
    // Download your image.      
    // Create some balls, and fill in the data members.
    // Start the animation thread.
    // Force a repaint.
  }

  public void run()
  {
    while ( true )
    {
      // Update the positions of all of the balls.
      // When ball leaves the screen, replace with a new one.
      // Force a repaint.
      // Sleep this thread for a while.
    }
  }

  public void paint( Graphics g )
  {
    // Paint all of the balls.
  }
}

0
 

Expert Comment

by:hateli
ID: 1226995
I will try and be in touch with you .

Thanks a lot.
0
 

Author Comment

by:yeda
ID: 1226996
i AM HAVING PROBLEM IN REGENERATING THE BALLS ! PLEASE HELP ME WITH FULL CODE !

0
 

Expert Comment

by:usk
ID: 1226997
I just created the same applet for "hateli".

The applet and source code is located at :

www.cybersite.dk/examples/dropball.htm

(I would like some points for it, if you can use it)


0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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 …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now