tags:

views:

38

answers:

1
    private void drawGrid(){
    for(int i = 0; i<3; i++){
        GLine line = new GLine(0,0,21*i,211*i);
        add(line);
    }
}

Is there a way to change the name of the gline I create each time the for loop is run?

+2  A: 

You can use an array of GLine, and store a new GLine in each index:

private void drawGrid(){

   GLine[] glines = new GLine[3];

    for(int i = 0; i<3; i++){
        GLine line = new GLine(0,0,21*i,211*i);
        glines [i] = line;
    }
}

This way, glines[0] referes to the first GLine, glines[1] refers to the second one etc.

Oded
Perfect thanks oded
Alex
+1 for being able to figure out the question
Kris