My First Java game uses too much CPU usage. Please Help !!

http://dl.dropbox.com/u/15738531/Screen%20Shot%202011-11-25%20at%208.48.32%20PM.png

Ok, I know this is a noob question, but I really can’t figure out the way to fix this problem. My game is running fine on my computer but it heats my CPU a lot which it shouldn’t. This is my first game I ever created and I started learning Java like 1-2 months ago so my previous experience in game programming is zero. I did some googling and I tried adding game loop to this and set the framerate at 50 fps (not quite sure I did it right or not). I assumed that the problem has to do something with the looping. Anyway, I’m waiting for some good suggestions.

Thanks

Here is the link to my game and code:
http://dl.dropbox.com/u/15738531/SkyFighter.zip

Get a better CPU cooler?

Hi

Thread.sleep() does not allow to reduce the consumption of CPU time, the thread ceases execution.

Could you post your game loop here on JGO in code blocks?

 code goes here 

EDIT: It’s not your program’s fault, it’s your computer. I ran the JAR file and barely uses my CPU at all. Are you on a laptop?

I’m using Macbook Pro 13" (Early 2011 Model) and Here’s my code:

 
public void RunIt(){
    	final int FRAMES_PER_SECOND = 50;
        final int SKIP_TICKS = 1000 / FRAMES_PER_SECOND;
    	long next_game_tick = System.currentTimeMillis();;
    	long sleep_time = 0;
    	while(true){
    		
    		gameUpdate();
    		 next_game_tick += SKIP_TICKS;
    	     sleep_time = next_game_tick - System.currentTimeMillis();
    	     if( sleep_time >= 0 ) {
    	            try {	Thread.sleep(sleep_time);	} catch (InterruptedException e) { }
    	     }
    	     else {  }
    	}

    }

  public void gameUpdate(){
    	  //Background Animation Control
    	for (int i=0; i< backgnd.size(); i++){
    		
    		if(((Background) backgnd.get(i)).getY()<cont.getHeight()){
    			((Background) backgnd.get(i)).move();	
  
    		}
    		else{
    			backgnd.add(new Background(0, -((Background) backgnd.get(i)).getImg().getHeight(cont) ));
    			backgnd.remove(i);		
    		}
    	}
    	
    	  //Cloud Animation Control
    	for (int i=0; i< clouds.size(); i++){
    		if(((Cloud) clouds.get(i)).getY()<cont.getHeight()){
    			((Cloud) clouds.get(i)).move();		
    		}
    		else{
    			clouds.add(new Cloud((int)(Math.random()*getWidth()), -(int)(Math.random()*getWidth())));
    			clouds.remove(i);
    		}
    	}
    	  //High Cloud Animation Control
    	for (int i=0; i< highclouds.size(); i++){
    		if(((HighCloud) highclouds.get(i)).getY()<cont.getHeight()){
    			((HighCloud) highclouds.get(i)).move();		
    		}
    		else{
    			highclouds.add(new HighCloud((int)(Math.random()*getWidth()), -(int)(Math.random()*getWidth())));
    			highclouds.remove(i);
    		}
    	}	
    	
    	  //Bullet Speed Control
    	Rectangle bllt;
    	Rectangle enmy;
        for (int i=0 ; i < bullets.size(); i++){   
            if (((Bullet) bullets.get(i)).getY()>0){
            	
                ((Bullet) bullets.get(i)).move();
                bllt = ((Bullet) bullets.get(i)).getBounds();
               
                //nested enemy loop
                for(int a=0; a < enemies.size(); a++){
                	enmy = ((Enemy) enemies.get(a)).getBounds();
                	
                	if(enmy.intersects(bllt)){
                		bullets.remove(i);
                		
                		enemies.remove(a);
                		enemies.add(new Enemy((int)(Math.random()*getWidth()), -(int)(Math.random()*getWidth())));     			
                	}
                }
            }
            else {
            	bullets.remove(i);        
            }
        }     
        
        for (int i=0; i< enemies.size(); i++){
    		if(((Enemy) enemies.get(i)).getY()<cont.getHeight()){
    			
    			((Enemy) enemies.get(i)).move();		
    			
    			
    		}
    		else{
    			enemies.add(new Enemy((int)(Math.random()*getWidth()), -(int)(Math.random()*getWidth())));
    			enemies.remove(i);
    		}
    	}
        
        //----
        
        //Ship Coordinating
        if(pressleft == true){
            ship.moveLeft();
        }
        
        if(pressright == true){
            ship.moveRight();
        }
        
        if(pressup == true){
            ship.moveUp();
        }
        
        if(pressdown == true){
            ship.moveDown();
        } 
        
        if(pressx == true){       	
        	
        }        
        
        repaint();
    }

Nothing looks wrong, and as I said earlier, the jar works fine with barely any CPU usage. Try looking how much CPU usage the java process is using up.