This is my code:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class BlackjackGUI {
JButton hit;
JButton stand;
public static void main (String[] args) {
BlackjackGUI blackjack = new BlackjackGUI();
blackjack.go();
}
public void go() {
JFrame frame = new JFrame();
frame.setSize(500,500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
JPanel tophalf = new JPanel();
JPanel bottomhalf = new JPanel();
JLabel guititle = new JLabel (" Blackjack V1.0 ");
JPanel dealerhandtitle = new JPanel ();
JPanel dealerhandcards = new JPanel ();
JPanel dealerside = new JPanel();
JPanel playerside = new JPanel();
JPanel playerhandtitle = new JPanel ();
JPanel playerdealerarea = new JPanel ();
JPanel playerhandcards = new JPanel ();
JPanel hitstand = new JPanel ();
JButton Hit = new JButton(" Hit ");
JButton Stand = new JButton("Stand");
JLabel dealerhandtitletext = new JLabel ("Dealer's Hand");
JLabel dealerhandcardstext = new JLabel ("Dealer's Cards");
JLabel playerhandtitletext = new JLabel ("Player's Hand");
JLabel playerhandcardstext = new JLabel ("Player's Cards");
frame.getContentPane() .add(BorderLayout.NORTH, tophalf);
frame.getContentPane() .add(BorderLayout.SOUTH, bottomhalf);
tophalf.setBackground(Color.white);
bottomhalf.setBackground(Color.darkGray);
tophalf.add(guititle);
bottomhalf.add(BorderLayout.WEST, Hit);
bottomhalf.add(BorderLayout.EAST, Stand);
frame.getContentPane() .add(BorderLayout.CENTER, playerdealerarea);
playerdealerarea.add(BorderLayout.NORTH, dealerside);
playerdealerarea.add(BorderLayout.SOUTH, playerside);
dealerside.add(BorderLayout.NORTH, dealerhandtitle);
dealerside.add(BorderLayout.SOUTH, dealerhandcards);
playerside.add(BorderLayout.NORTH, playerhandcards);
playerside.add(BorderLayout.SOUTH, playerhandtitle);
dealerhandtitle.add(dealerhandtitletext);
dealerhandcards.add(dealerhandcardstext);
playerhandtitle.add(playerhandtitletext);
playerhandcards.add(playerhandcardstext);
frame.setVisible(true);
}
}
I am trying to stack my panels vertically to eventually make a blackjack game. Could someone please explain to me why the panels are stacking sideways rather than vertically? Thank you so much for the help.


LinkBack URL
About LinkBacks
Reply With Quote