java - Cast a random object from ArrayList<> -


hello,

i need advice how create method or change body code cast random object arraylist<>(); superclass. make program choose random enemy arraylist. (this code works, sets labels last created enemy. well, hope made self clear, , sorry english ;) kind regards!

so superclass basicly "body" of program jframe , labels:

nameenemytextlabel = new jlabel(enemy.getname(enemy.nameenemy)); nameenemytextlabel.setbounds(150, 5, 100, 30); add(nameenemytextlabel); 

and subclass this:

class enemy extends body{  static int levelenemy; static string nameenemy;  static int strengthenemy; static int agilityenemy; static int staminaenemy; static int initiativeenemy;  static int healthenemy; static int damageenemy;  // enemy stats - strength public enemy() { }  public enemy (string ne, int le, int se, int ae, int ste, int ie) {      nameenemy = ne;     levelenemy =le;      strengthenemy = se;     agilityenemy = ae;     staminaenemy = ste;     initiativeenemy = ie;  } 

then methods return name, level, etc. , after that, arraylist:

//i tryting put arraylist inside main method , outside//      public static arraylist<enemy> wrogowie = new arraylist<enemy>();          enemy enemy_01 = new enemy ("wróg 1",1,1,1,1,1);         enemy enemy_02 = new enemy ("wróg 2",2,2,2,2,2);         enemy enemy_03 = new enemy ("wróg 3",3,3,3,3,3);   public static void main(string[] args) {      wrogowie.add(enemy_01);     wrogowie.add(enemy_02);     wrogowie.add(enemy_03);  } 

}


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -