I've created a basic program with java that creates a five card poker hand and then displays them in a JFrame. I'm essentially displaying five images in a frame, but instead of displaying in the positions that I think they should be in, they look like
Any help would be appreciated, thanks!
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.*;
import java.awt.Color;
import javax.swing.border.SoftBevelBorder;
import javax.swing.border.BevelBorder;
import java.awt.Point;
import java.net.URL;
import javax.smartcardio.Card;
public class PokerGUI extends JFrame {
private static JPanel contentPane;
private PokerBoard board;
private static JLabel[] displayCards;
private static Point[] cardCoords;
private static final int LAYOUT_WIDTH_INC = 100;
private static final int LAYOUT_HEIGHT_INC = 125;
private static final int LAYOUT_TOP = 30;
private static final int LAYOUT_LEFT = 30;
private static boolean[] selections;
public PokerGUI(PokerBoard gameBoard) {
board = gameBoard;
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 530, 252);
contentPane = new JPanel();
setResizable(false);
setTitle("SUPER COOL POKER GAME!!!!");
contentPane.setBackground(Color.DARK_GRAY);
contentPane.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, new Color(0, 255, 0), new Color(0, 255, 0), new Color(0, 128, 0), new Color(0, 128, 0)));
contentPane.setToolTipText("Super Cool Poker!!");
contentPane.setLayout(new BorderLayout(0, 0));
selections = new boolean[5];
displayCards = new JLabel[5];
Point one = new Point(30, 30);
Point two = new Point(130, 30);
Point three = new Point(230, 30);
Point four = new Point(330, 30);
Point five = new Point(430, 30);
cardCoords = new Point[]{one, two, three, four, five};
init();
for (int k = 0; k < 5; k++) {
String cardImageFileName = imageFileName(board.cardAt(k), selections[k]);
URL imageURL = getClass().getResource(cardImageFileName);
if (imageURL != null) {
ImageIcon icon = new ImageIcon(imageURL);
displayCards[k].setIcon(icon);
displayCards[k].setVisible(true);
} else {
throw new RuntimeException("Card image not found: \"" + cardImageFileName + "\"");
}
}
setContentPane(contentPane);
}
private static void init() {
for (int k = 0; k < 5; k++) {
displayCards[k] = new JLabel();
contentPane.add(displayCards[k]);
displayCards[k].setBounds(cardCoords[k].x, cardCoords[k].y, 73, 97);
//displayCards[k].addMouseListener(new MyMouseListener());
selections[k] = false;
}
}
private String imageFileName(Card c, boolean isSelected) {
String str = "cards/";
if (c == null) {
return "cards/back1.GIF";
}
str += c.rank() + c.suit();
if (isSelected) {
str += "S";
}
str += ".GIF";
return str;
}
}
The other classes shouldn't really be important because my main issue is just getting the five images to display in the correct places.