1

I know this is a very simple thing, but I can't see any examples of doing this with strings. This is beyond the basic exercise in my self imposed homework, and more advanced, but I know it can be done so I just want to go ahead and learn these arrays :-D

I'm trying to change the value if the string in the GLabel below:

private void printSubclassBoxes(){
        String[] anArray = {"GraphicsProgram", "ConsoleProgram", "DialogProgram"};

        int  coordinateX = ((getWidth() - BOX_WIDTH) /4);
        int otherCoordinateX = coordinateX;

        for ( int i = 0 ; i < 3; i++){

            double coordinateY = (getHeight() / 2);     
            GRect classBox = new GRect (coordinateX, coordinateY, BOX_WIDTH, BOX_HEIGHT);

            GLabel classLabel = new GLabel ("ARRAY WILL GO HERE");
            double labelCoordinateX = (coordinateX + ((classBox.getWidth() / 2) - (classLabel.getWidth() / 2)));
            double labelCoordinateY = (coordinateY + ((classBox.getHeight() / 2) + (classLabel.getAscent() / 2)));
            add(classBox);
            add(classLabel, labelCoordinateX, labelCoordinateY);
            coordinateX = otherCoordinateX + coordinateX;

        }   

    }

Thanks for the help!

3
  • Can u pls explain what exactly is the problem? Commented Feb 22, 2010 at 5:43
  • Maybe I'm missing something, but do you mean something like GLabel classLabel = new GLabel(anArray[i]); ? Commented Feb 22, 2010 at 5:44
  • That was exactly it spong-I knew it was a total noob thing, but I just couldn't figure it out. Commented Feb 22, 2010 at 5:48

1 Answer 1

2

I think you want this:

GLabel classLabel = new GLabel (anArray[i]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.