How can I repeat a for loop, once it's terms has been fulfilled???

Well.. I've posted 2 different exceptions about this game today, but I managed to fix them all by myself, but now I'm facing another problem, which is NOT an error, but just a regular question.. HOW CAN I REPEAT A FOR LOOP ONCE IT HAS FULFILLED IT'S TERMS OF RUNNING?!
I've been trying many different things, AND, the 'continue' statement too, and I honestly think that what it takes IS a continue statement, BUT I don't know how to use it so that it does what I want it too.. -.-'
Anyway.. Enought chit-chat. I have a nice functional game running that maximum allows 3 apples in the air in the same time.. But now my question is: How can I make it create 3 more appels once the 3 first onces has either been catched or fallen out the screen..?
Here's my COMPLETE sourcecode, so if you know just a little bit of Java you should be able to figure it out, and hopefully you'll be able to tell me what to do now, to make it repeat my for loop:
Main.java:
import java.applet.*;
import java.awt.*;
@SuppressWarnings("serial")
public class Main extends Applet implements Runnable
     private Image buffering_image;
     private Graphics buffering_graphics;
     private int max_apples = 3;
     private int score = 0;
     private GameObject player;
     private GameObject[] apple = new GameObject[max_apples];
     private boolean move_left = false;
     private boolean move_right = false;
    public void init()
        load_content();
        setBackground(Color.BLACK);
     public void run()
          while(true)
               if(move_left)
                    player.player_x -= player.movement_speed;
               else if(move_right)
                    player.player_x += player.movement_speed;
               for(int i = 0; i < max_apples; i++)
                   apple.apple_y += apple[i].falling_speed;
               repaint();
               prevent();
               collision();
          try
          Thread.sleep(20);
          catch(InterruptedException ie)
          System.out.println(ie);
     private void prevent()
          if(player.player_x <= 0)
          player.player_x = 0;     
          else if(player.player_x >= 925)
          player.player_x = 925;     
     private void load_content()
     MediaTracker media = new MediaTracker(this);
     player = new GameObject(getImage(getCodeBase(), "Sprites/player.gif"));
     media.addImage(player.sprite, 0);
     for(int i = 0; i < max_apples; i++)
     apple[i] = new GameObject(getImage(getCodeBase(), "Sprites/apple.jpg"));
     try
     media.waitForAll();     
     catch(Exception e)
          System.out.println(e);
     public boolean collision()
          for(int i = 0; i < max_apples; i++)
          Rectangle apple_rect = new Rectangle(apple[i].apple_x, apple[i].apple_y,
apple[i].sprite.getWidth(this),
apple[i].sprite.getHeight(this));
          Rectangle player_rect = new Rectangle(player.player_x, player.player_y,
player.sprite.getWidth(this),
player.sprite.getHeight(this));
          if(apple_rect.intersects(player_rect))
               if(apple[i].alive)
               score++;
               apple[i].alive = false;
               if(!apple[i].alive)
               apple[i].alive = false;     
     return true;
public void update(Graphics g)
if(buffering_image == null)
buffering_image = createImage(getSize().width, getSize().height);
buffering_graphics = buffering_image.getGraphics();
buffering_graphics.setColor(getBackground());
buffering_graphics.fillRect(0, 0, getSize().width, getSize().height);
buffering_graphics.setColor(getForeground());
paint(buffering_graphics);
g.drawImage(buffering_image, 0, 0, this);
public boolean keyDown(Event e, int i)
     i = e.key;
if(i == 1006)
move_left = true;
else if(i == 1007)
     move_right = true;
          return true;     
public boolean keyUp(Event e, int i)
     i = e.key;
if(i == 1006)
move_left = false;
else if(i == 1007)
     move_right = false;
return true;
public void paint(Graphics g)
g.drawImage(player.sprite, player.player_x, player.player_y, this);
for(int i = 0; i < max_apples; i++)
     if(apple[i].alive)
          g.drawImage(apple[i].sprite, apple[i].apple_x, apple[i].apple_y, this);
g.setColor(Color.RED);
g.drawString("Score: " + score, 425, 100);
public void start()
Thread thread = new Thread(this);
thread.start();
@SuppressWarnings("deprecation")
     public void stop()
     Thread thread = new Thread(this);
thread.stop();
GameObject.java:import java.awt.*;
import java.util.*;
public class GameObject
public Image sprite;
public Random random = new Random();
public int player_x;
public int player_y;
public int movement_speed = 15;
public int falling_speed;
public int apple_x;
public int apple_y;
public boolean alive;
public GameObject(Image loaded_image)
     player_x = 425;
     player_y = 725;
     sprite = loaded_image;
     falling_speed = random.nextInt(10) + 1;
     apple_x = random.nextInt(920) + 1;
     apple_y = random.nextInt(100) + 1;
     alive = true;
And now all I need is you to answer my question! =)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

package forums;
import java.util.Random;
import javax.swing.Timer;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class VimsiesRetardedAppleGamePanel extends JPanel implements KeyListener
  private static final long serialVersionUID = 1L;
  private static final int WIDTH = 800;
  private static final int HEIGHT = 600;
  private static final int MAX_APPLES = 3;
  private static final Random RANDOM = new Random();
  private int score = 0;
  private Player player;
  private Apple[] apples = new Apple[MAX_APPLES];
  private boolean moveLeft = false;
  private boolean moveRight = false;
  abstract class Sprite
    public final Image image;
    public int x;
    public int y;
    public boolean isAlive = true;
    public Sprite(String imageFilename, int x, int y) {
      try {
        this.image = ImageIO.read(new File(imageFilename));
      } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException("Bailing out: Can't load images!");
      this.x = x;
      this.y = y;
      this.isAlive = true;
    public Rectangle getRectangle() {
      return new Rectangle(x, y, image.getWidth(null), image.getHeight(null));
  class Player extends Sprite
    public static final int SPEED = 15;
    public Player() {
      super("C:/Java/home/src/images/player.jpg", WIDTH/2, 0);
      y = HEIGHT-image.getHeight(null)-30;
  class Apple extends Sprite
    public int fallingSpeed;
    public Apple() {
      super("C:/Java/home/src/images/apple.jpg", 0, 0);
      reset();
    public void reset() {
      this.x = RANDOM.nextInt(WIDTH-image.getWidth(null));
      this.y = RANDOM.nextInt(300);
      this.fallingSpeed = RANDOM.nextInt(8) + 3;
      this.isAlive = true;
  private final Timer timer = new Timer(200,
    new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        repaint();
  public VimsiesRetardedAppleGamePanel() {
    this.player = new Player();
    for(int i=0; i<MAX_APPLES; i++) {
      apples[i] = new Apple();
    setBackground(Color.BLACK);
    setFocusable(true); // required to generate key listener events.
    addKeyListener(this);
    timer.setInitialDelay(1000);
    timer.start();
  public void keyPressed(KeyEvent e)  {
    if (e.getKeyCode() == e.VK_LEFT) {
      moveLeft = true;
      moveRight = false;
    } else if (e.getKeyCode() == e.VK_RIGHT) {
      moveRight = true;
      moveLeft = false;
  public void keyReleased(KeyEvent e) {
    moveRight = false;
    moveLeft = false;
  public void keyTyped(KeyEvent e) {
    // do nothing
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    //System.err.println("DEBUG: moveLeft="+moveLeft+", moveRight="+moveRight);
    if ( moveLeft ) {
      player.x -= player.SPEED;
      if (player.x < 0) {
        player.x = 0;
    } else if ( moveRight ) {
      player.x += player.SPEED;
      if (player.x > getWidth()) {
        player.x = getWidth();
    //System.err.println("DEBUG: player.x="+player.x);
    Rectangle playerRect = player.getRectangle();
    for ( Apple apple : apples ) {
      apple.y += apple.fallingSpeed;
      Rectangle appleRect = apple.getRectangle();
      if ( appleRect.intersects(playerRect) ) {
        if ( apple.isAlive ) {
          score++;
          apple.isAlive = false;
    g.drawImage(player.image, player.x, player.y, this);
    for( Apple apple : apples ) {
      if ( apple.isAlive ) {
        g.drawImage(apple.image, apple.x, apple.y, this);
    g.setColor(Color.RED);
    g.drawString("Score: " + score, WIDTH/2-30, 10);
  private static void createAndShowGUI() {
    JFrame frame = new JFrame("Vimsies Retarded Apple Game");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(new VimsiesRetardedAppleGamePanel());
    frame.pack();
    frame.setSize(WIDTH, HEIGHT);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  public static void main(String[] args) {
    SwingUtilities.invokeLater(
      new Runnable() {
        public void run() {
          createAndShowGUI();
}Hey Vimsie, try resetting a dead apple and see what happens.

Similar Messages

  • How can I delay my MBP from hibernating until the lid has been closed for a set period of time?

    After extensive research, I have been unable to solve this problem and I'm hoping someone can explain this to me.   Everytime I close the lid on my 13-inch, Early 2011 Macbook Pro, it immediately starts to write to disk (solid light on the front) for several seconds until it finally goes into Hibernate mode (flashing light on the front).  The problem is, I frequently close the lid, then immediately reopen it within 15-30 seconds to resume typing or to add something I may have forgotten.   Each time I reopen the lid before the light has started flashing, the MBP wakes for a moment, and allows me to resume typing.  However, the Hibernation process has already begun and within 30 seconds, the screen goes blank.   I have to wake it AGAIN, which is very annoying.
    Based on my research, I could use pmset to change the hibernatemode to 0 (it is currently set at 3).   However, I dont wish to disable hibernate mode completely; I DO want it to save a hibernation image to disk if it happens to run out of battery, so that when I resume I havent lost anything.   
    I then researched using standby and standbydelay to attempt a delay of the write to disk when going into standby mode.   According to the pmset manual:
    standby causes kernel power management to automatically hibernate a machine after it has slept for a
         specified time period. This saves power while asleep
    standbydelay specifies the delay, in seconds, before writing the hibernation image to disk and powering
         off memory for Standby
    I then set these values as below, expecting the laptop to wait 4200 seconds (70 minutes) before trying to write to disk when I close the lid:
    standbydelay         4200
    standby              1
    Unfortunately, that did not work either.   If I close the lid, the light glows solid immediately (indicating it is writing to disk), and if I try to reopen the lid before it is done, it will wake and seem fine, then 30 seconds later it goes blank right in the middle of me typing something.   I usually have to click the mouse several times, or even the power button to re-wake it.  
    I do have InsomniaX installed, for when I want to close the lid and keep the machine awake permanently (while watching videos on airplay) and I have tried quitting that application to test this.  However, when I close/reopen the lid..the result is the same.   I cant keep InsomniaX enabled all the time, because it will never go to sleep when I truly want it to.   If I am not using InsomniaX, I just want to delay hibernation until he lid has been closed for a set period (say 15 minutes or more).  If I have not reopened the lid within that time, I want it to write to disk and go into hibernation mode.  And if the battery runs all the way out, I want it to go into hibernation mode before shutting down so I can recover.
    I would appreciate any help in solving this problem.  Also any insight as to why the standbydelay setting above did not work.   Thanks!

    Whats with the MBP lid? Dont close it ... if you're so concerned! Just go to System Preferences/Energy Saver and set it to how you like it.

  • How can we find out data in an editable ALV grid has been changed or not?

    Hi Experts,
    How can we find out whether a data in an editable ALV grid has been changed or not.
    I am using the
    FM -> REUSE_ALV_GRID_DISPLAY_LVC
    for ALV display.
    I have to chekc whther data has been changed or not befor saving. if changed then only i want to
    SAVE
    . I cannot use the internal table comparison method for this purpose also i am not using OOP ALV.
    So kindly sugest me an alternative.
    Thanks and Regards,
    Shahana

    Hi,
    Thanks for your answer. I already saw this post.
    See this method.
    CALL METHOD reuse_alv_grid->check_changed_data
    IMPORTING
    e_valid = lv_check.
    This will update the internal table with the edited values. Then we can go for internal table comparison.
    But my scenario will not allow me for itab comparisons.I just want to know the ALV data has been changed or not.
    Regards,
    Shahana

  • How can I update a quicktime movie placed in Keynote, that has been modified outside of Keynote??

    HI! I really like Keynote for quicktime playback during a tv/film shoot, and use it frequently on set.
    Media assets change frequently though, and it would be nice if the movies I place would update along with the external source.
    How can this happen in Keynote? Seems like even if you save the file without copying audio/video into document, it still somehow references the initial placed movie.
    Thanks for your help solving this problem, would be great if this app worked like every other app that imports external media.

    That's a shame. It takes some tweaking, but PowerPoint can do this. I know it's not something that is needed all the time, but it's something I've needed on a few occasions. I wonder how well the timing would work out if I broke the video up into sub clips and simply assigned a clip to each slide? It's a lot more work and I suspect I'll pick up some clips and pops during the slide changes.
    Keynote is still far better at what it does than PowerPoint, but do I ever wish it could do this so I could really show it off to people.
    Thanks for the reply!

  • How can we change an old apple id in icloud that has been set in iphone and we don't have password of it?

    hi
    a friend of mine has bought a second hand iphone 5s . in icloud setting an old apple id has been set.he'd like to change it with his own , he isn't able to change it because the password of old apple id is required , and every 10 sec a message is appeared that needs a password ( find my iphone ). he has set his own apple id in itunes  store , but in i cloud he couldn't find a person that he has bought it from .how can we fix this problem .
    i'm looking forward to hearing from you .
    thank you
    sincerely

    That is "activation lock". You won't be able to use the iPhone unless this is cleared by the original owner.

  • HT4847 How can I delete an iCloud backup of a device that has been wiped and sold?

    I have wiped my old iPhone and it has already been repurposed. How can I delete its backup from iCloud now?

    You'll probably have to get help from Apple on that.  If you have an iPhone 5 and are within your 90-day free phone support window, get ahold of iCloud support and see if they can fix this at their end: http://www.apple.com/support/icloud/contact/.

  • How can i view a attached file in OAF pages which has been attached

    Dear all,
    Hope you are well.
    i have a table region from that i have attached a file named"file1.text" against a primary key.
    now i want to view that attached file in a oaf page.
    how can i view that attachment.
    would you please explain

    Hi again,
    Personalize that table
    1-Add Attachment Image column
    2-Set the *View Instance (ViewObject that feeds table)
    3-Add Entity under the Attachment image
    4-Set *Entity as same with your entity value
    5-Insert Allowed =>false, Update Allowed => false Show All => true
    6-Add a primary key under the Entity
    7-Set View Attribute with your primary key column like PersonId
    Thanks.
    Anil

  • How can I find out if the rollback optimal parameter size has been set ?

    What is the command to find out if the rollback optimal parameter size has been set? And what is the command to find out what is the rollback optimal parameter set to?

    You can find the OPTIMAL size in v$rollstat.optsize

  • How can I know if a certain tick in a sequence has been reached during playback?

    I'm using the sequencer to play a sequence and I need to jump to an other part of the sequence when a certain tick is reached. Imagine a loop that when we reach tick number "y" we jump back to tick number "x". But I'm not doing a loop so the built in looping methods won't work for me because sometimes I have to jump forward and that is not allowed .
    At the moment I'm using a swing timer that fires a getTickPosition() every millisecond until I reach my desired tick but this is giving me slightly inconsistent results and I have a feeling it is using a lot of CPU for a fairly simple task.
    I wish there was an event listener that would notify me when a certain tick is processed by the sequencer or even if I could be notified each time a new tick is processed so that I can do a check to see if it was the tick I was waiting for.
    I wonder how the sequencer does it internally for knowing when the loop end is.
    Any suggestions or workarounds would be greatly appreciated.

    Just to make it more clear, the SQL we were looking for is this:
    Select
    From
      OJDT
    Where
      OJDT.TransId Not In ( Select VPM2.DocEntry From VPM2 Where VPM2.InvType = 30 )
      And
      OJDT.TransType = 30

  • How can I delete an ODBC data source after 10g client has been uninstalled?

    I uninstalled the 10g client and now when I attempt to delete the ODBC data source, I get an error: "The setup routines for the Oracle in Oraclient10g_home2 ODBC driver could not be found. Please reinstall the driver. I re-installed the client and I get the same error, but I had to specify a new home. I still get the error. Anyone have an answer or a workaround to deleting the ODBC entry so that I can re-create with the same name later under the 9i client?

    I have the same problem... and nobody gots the point:
    1st. the ODBC and the client/home exists on the machine...
    2nd. the client/home is unistalled and so...
    3rd. tada! Now we have a impossible-to-unistall ODBC entry!
    That is happening on a Windows, at last to me...
    Please, help us if someone knows how to remove this ODBC entry... if know how to DO the stuff (permissions, system, all that things is answered above).
    Best regards,
    Bruno Araujo

  • How can I connect my old macbook pro hard drive, which has been removed, to a new computer

    I had to remove the hard drive from my 2010 Macbook Pro due to damages motherboard (son spilled apple juice). I bought a new macbook pro and need to pull some data offf the old on. I had the hard drive removed and see the pin connector. What type of cable do I need to connect this via usb, firewire or thunderbolt

    "Newer Technology Universal 5.25/3.5/2.5" Hard Drive & Optical Drive to USB2 Adapter w/Power. Everything you need to Plug and Play any SATA/ATA/IDE/ATAPI Drive via USB 2.0/1.1 port. Fast, Simple, Plug & Play. GREAT for transferring data, etc. (NWTU2NV2SPATA)" - http://eshop.macsales.com/item/Newer%20Technology/U2NV2SPATA/

  • How can I get my music back if my Apple ID has been changed

    My music isn't popping up. Apple said I owe money that I tried paying it didn't work so I made a new ID! I need help I payed for 123 songs!

    You pay what you owe. If you're having a problem doing that, you call iTunes store support and you make arrangements to settle your debt.
    Of course, if you had it in the iTunes library on your computer, it wouldn't be a problem...

  • How can i find the number of times my volume license has been activiated?

    Volume licensing activations.

    Try contacting Adobe support to see if they can help.
    Here are some links to help make contact:
    http://www.adobe.com/support/chat/ivrchat.html
    http://www.adobe.com/support/download-install/supportinfo/

  • In DPS/Indesign for iPad - How can i create a button that once tapped, will pre-populate an email?

    In DPS/Indesign for iPad - How can i create a button that once tapped, will pre-populate an email? like when you tap a recipe in Marth Stewart Every Day Food for example....

    http://forums.adobe.com/message/4190932

  • How can we repeat specific page number of pdf file by using FDF Toolkit for Windows?

    how can we repeat specific page number of pdf file by using FDF Toolkit for Windows?

    let's say a registration form, there is only 1 full address provided in my registration pdf, but applicant could have more than 1 address, so i have to make it more flexible to extend the address page no matter how many addresses that applicant provided, i have use adobe acrobat pro to edit the form properties. but dont know how to extend/duplicate a page in felxible times.
    Please advise~ tks so much!!! George

Maybe you are looking for

  • Variable Substitution File Receiver Adapter

    Hi, I am in the process of implementing a scenario involving the conversion of a .jpg file to .bmp. In my scenario, I'd like to the .bmp file name to be dynamically controlled; therefore, I have used the Variable Substitution option in the File Recei

  • ALV Header Line

    can i add 2 header lines in ALV Reporting, if so then how give example. abhishek suppal

  • Field response playing Hide & Seek.

    Hi, I am using Acrobat Pro X to create a form.  This was distributed and some of the respondants replied with some problems. Problem 1: Field responses. Respondents replied they filled in every field. But I saw some missing. It was only when I clicke

  • My iPhone4 has 3G but Safari won't load any data, why is this?

    My iPhone4 works fine in some places, but whenever I'm in the house and have 3G, safari won't load. I just get a message saying 'safari could not open the page because the server stopped responding' can anyone help me fix this? Thank you

  • Lightroom nomore synchronize with LR mobile (ipad)

    Since yesterday, LR5.5 indicates 21 pictures to synchronize.. but nothing happens. (Message is "21 images synchronizing". From LR mobile to LR desktop, the little cloud icon allow the right synchronization but in opposite way it doesn't work. Connect