开发者

Inserting string array value in for loop in java

开发者 https://www.devze.com 2022-12-21 00:54 出处:网络
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

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);   开发者_JAVA技巧  
            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!


I think you want this:

GLabel classLabel = new GLabel (anArray[i]);
0

精彩评论

暂无评论...
验证码 换一张
取 消