Question

Problem: I need to have an integer that can be changed to be painted on screen.

What I Want To Do: Label an X Axis on a chart

Variables Used:

  • lengthCountArray = An int[] array
  • calcXWidth(lengthCountArray) = the amount to move along when painting the next integer

Current Code:

for(int a = 1; a < lengthCountArray.length; a++){
            x = 50 + calcXWidth(lengthCountArray);;
            y = 450;

            g.drawString(s, x, y);

        }

What I've Tried 1:

for(int a = 1; a < lengthCountArray.length; a++){
            String s = String.valueOf(a); 
            x = 50 + calcXWidth(lengthCountArray);;
            y = 450;

            g.drawString("" + s, x, y);

        }

Comment: Issue is, you can't change a string after assigning it :(

What I've tried 2:

for(int a = 1; a < lengthCountArray.length; a++){
            x = 50 + calcXWidth(lengthCountArray);;
            y = 450;

            g.drawString("" + <int a>, x, y);

        }

If you require any further information, please do not hesitate to ask! Thank you in advance

Was it helpful?

Solution

In the comments I saw this post, which was the resolution to the problem.

"For me it's not clear. When you want to draw an int, then you can do g.drawSting(String.valueOf(theInt), x, y) - what's wrong with that?" – Marco13 Mar 5 at 22:42

Thank you for the post Marco13! Really helped me!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top