import java.awt.*; import java.awt.event.*; import com.genuts.gameui.*; /** * Display a simple example of sprites.
* Loads the balls image (the size for each ball is 31x31), * creates the playfield and 20 balls. */ public class BouncedSprites { public static void main (String[] args) { Frame frame = new Frame("BouncedSprites"); Panel panel = new Panel(); // Creates the playfield PlayField playfield = new PlayField(310, 248); playfield.setBackground(Color.black); // Loading images Image ballImage = Toolkit.getDefaultToolkit().getImage("ball.gif"); MediaTracker tracker = new MediaTracker(playfield); tracker.addImage(ballImage, 0); try { tracker.waitForID(0); } catch (InterruptedException e) { System.out.println("Loading interrupted"); } // Creates 20 balls (4 lines / 5 columns) for (int i = 0; i < 4; i++) { for (int j = 0; j < 5; j++) { Sprite sprite = new MovingWrapper(new AnimatedSprite(ballImage, 4, 3, (int) (Math.random()*5)), 1, 1); int x = j*62 + 15; int y = i*62 + 15; sprite.setPosition(x, y); playfield.addSprite(sprite); } } // Displays the playfield panel.add(playfield); frame.add(panel); // Activate the playfield playfield.setPause(false); //To close the frame properly frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); frame.pack(); frame.show(); } }