We are making a card game and created two JLabel
objects to represent the dealer and player cards but both panels appear on top of each other, and we can't figure out how to move them. Also, the background color for the frame was set to green but the panels have a white background. :(
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setPreferredSize(new Dimension(1000, 500));
JButton hitButton = new JButton("Hit");
hitButton.setBounds(100,400,50,50);
frame.add(hitButton);
JButton standButton = new JButton("Stand");
standButton.setBounds(400,400,75,50);
frame.add(standButton);
JButton doubleDownButton = new JButton("Double down");
doubleDownButton.setBounds(700,400,175,50);
frame.add(doubleDownButton);
game = new BlackjackGame();
JPanel panel1 = new JPanel();
JLabel dealerCard1 = new JLabel (game.getDealerCard1().getImage());
dealerCard1.setFont(new Font("Serif", Font.PLAIN, 60));
JLabel dealerCard2 = new JLabel ("\ud83c\udca0");
dealerCard2.setFont(new Font("Serif", Font.PLAIN, 60));
panel1.add(dealerCard1);
panel1.add(dealerCard2);
panel1.setLocation(300, 150);
frame.add(panel1);
JPanel panel2 = new JPanel();
JLabel playerCard1 = new JLabel (game.getPlayerCard1().getImage());
playerCard1.setFont(new Font("Serif", Font.PLAIN, 60));
JLabel playerCard2 = new JLabel (game.getPlayerCard2().getImage());
playerCard2.setFont(new Font("Serif", Font.PLAIN, 60));
panel2.add(playerCard1);
panel2.add(playerCard2);
frame.add(panel2);