Search code examples
javaswingfor-loopdrawstring

How do you use a drawString to repeat its character on multiple lines but then add another character as it goes down each line?


public class graphic {
    public static final int L = 10;

    public static void main(String[] args) {
        face(g,(L/2)*2, 20);
    }

    public static void face (Graphics g, int x, int y){
        int e = (x+1)*10;
        int d = x*3; 
        int h = y+8+(x-1)*16;
        for (int z= 2; z<x; z++){
            g.drawString("__/", ((e-(x*8))+d*8)+((x-3)*8)-24-(32*(z-2)),(h-(x-1)*16)+ (z*16));
        }
    }
}

With this forloop, I want to produce one __/ on the first line then on the second line two and so on until the eight line where it will print eight total and stop. So far it only prints one __/ on each line. What do I need to change in my code so that it will print __/ on one line and then increase by one on then next?


Solution

  • You simply use a variable you draw, and update the variable in the for loop.

    String str = "stuff";
    For(){
    Draw method you have
    Str = str + "stuff";
    }