All pastes #492695 Raw Edit

Untitled

public text v1 · immutable
·published 2007-05-17 11:03 UTC
rendered paste body
//class where I want to add the labels. Works in the constructor, but not the run method. 

import java.util.*;

public class CreateShips extends Thread{ 
	EnemyShip[] enemies = new EnemyShip[30];


	public CreateShips(){

	}

	public void run(){
		while(true){

			create();
			try{
				sleep((int)(Math.random()*4000+1000));
			}
			catch(Exception e){
				System.out.println("Couldn't sleep");
			}
		}
	}


	public void create(){
		for(int i = 0; i<enemies.length;i++){
			if(enemies[i]==null){
				enemies[i] = new EnemyShip();
				break;
			}
		}
	}
}


//constructor in the EnemyShip extends JLabel class

public EnemyShip(){
		System.out.println("The constructor is run");
		setIcon(enemyship);
		setBounds(300,300,200,100);
		SpaceShooter.game.add(this);
	}