java - drawString in loop writes only once instead of multiple times -
what code do?
for(int = 0; < enemysno; i++){ g.drawstring("\narray size: " + i, 200, 200); }
enemysno random number between 0 , 10, , works fine. problem is, loops once, stops adding new lines after first iteration.
as psuedo code, though starts 0. compares condition, if false, code, makes ++ iterations, repeats loop?
ultimatly, want add n objects array, can quite work simple array work!
a simple test proves loop indeed works intended:
public static void main(string[] args) { int enemysno = 5; (int = 0; < enemysno; i++) { system.out.println("lalala " + i); } }
this works fine producing
lalala 0 lalala 1 lalala 2 lalala 3 lalala 4
it kind of obvious, via debugging or such test determine loop entered desired numer of times. problem must in string display: drawstring method overwrites printed string each time.
it should obvious if checked numbers on output.
the solution?
use string builder concatenate partial strings , draw final string using drawstring method
Comments
Post a Comment