Convert a String to a specific picture, then displaying it as an icon in Jswing

Viewed 28

I am trying to create a Blackjack game in Jswing. I have made some code that creates a deck of cards and then randomizes them. I then add a .png to the end of the Card String so that it can be displayed as an image. My problem is with trying to convert the String (which the Array gives) to a image. I have tried doing (Array[pos]+".png") and the setting the icon to the aforementioned String. But this only displays a blank image.

What does this not work?

        int pos = 0;
    String faces[] = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "jack", "queen", "king", "ace"};
    String suits[] = {"hearts", "diamonds", "clubs", "spades"};

    String[] Array = new String[52];
    for (int j = 0; j < Array.length; j++) {
        Array[j] = faces[j % 13] + "_of_" + suits[j / 13];
    }

    List<String> StringList = Arrays.asList(Array);

    Collections.shuffle(StringList);

    StringList.toArray(Array);

    ImageIcon icon = new ImageIcon(Array[pos] + ".png");
    pCard1.setIcon(icon);
    info.setText(Array[pos] + ".png"); //=> Gives something like "jack_of_diamonds.png" which is the format for the name of the pictures.
0 Answers
Related