Я настраиваю пользовательский интерфейс для вспомогательной программы блэкджека, и хотя я знаю, что это не самый красивый способ сделать что-то, это имеет смысл. Расслоение для верхних слоев не работает должным образом. Какие-либо предложения? Левый должен иметь четыре слоя, а средний и правый должны иметь два слоя между клавиатурой и кнопками ввода. Изображение прилагается ниже.
import java.util.*;
import java.lang.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.*;
// main method, runs the program
class BlackjackHelper
{
public static void main(String\[\] args)
{
Frame21 game = new Frame21();
//pop window with rules of game
}
}
// JFrame Construction
class Frame21 extends JFrame
{
// create needed components of program
JLabel questionDisplay = new JLabel("What is your first card?");
JLabel actionDisplay = new JLabel("Enter your first card");
JLabel dealerCardText = new JLabel("Dealer's Card:");
JLabel dealerCardDisplay = new JLabel("N/A");
JLabel handOneText = new JLabel("Hand One:");
JLabel handOneDisplay = new JLabel("N/A");
JLabel handTwoText = new JLabel("Hand Two:");
JLabel handTwoDisplay = new JLabel("N/A");
JLabel statsText = new JLabel("Win %:");
JLabel statsDisplay = new JLabel("N/A");
JButton aceButton = new JButton("A");
JButton twoButton = new JButton("2");
JButton threeButton = new JButton("3");
JButton fourButton = new JButton("4");
JButton fiveButton = new JButton("5");
JButton sixButton = new JButton("6");
JButton sevenButton = new JButton("7");
JButton eightButton = new JButton("8");
JButton nineButton = new JButton("9");
JButton tenButton = new JButton("10");
JButton faceButton = new JButton("F");
JButton clearButton = new JButton("C");
JButton standButton = new JButton("Stand");
JButton hitButton = new JButton("Hit");
JButton doubleButton = new JButton("Double");
JButton splitButton = new JButton("Split");
JButton winButton = new JButton("Win");
JButton loseButton = new JButton("Lose");
JButton resetButton = new JButton("Reset All");
JButton enterButton = new JButton("Enter");
public Frame21()
{
// JFrame - the main area of the program
JFrame frame = new JFrame("Blackjack Helper");
// JPanel right - the rightside of the program
JPanel rightSide = new JPanel();
JPanel rightNorthSide = new JPanel();
rightNorthSide.setLayout(new GridLayout(3,4));
rightNorthSide.add(aceButton);
rightNorthSide.add(twoButton);
rightNorthSide.add(threeButton);
rightNorthSide.add(fourButton);
rightNorthSide.add(fiveButton);
rightNorthSide.add(sixButton);
rightNorthSide.add(sevenButton);
rightNorthSide.add(eightButton);
rightNorthSide.add(nineButton);
rightNorthSide.add(tenButton);
rightNorthSide.add(faceButton);
rightNorthSide.add(clearButton);
JPanel rightSouthSide = new JPanel();
rightSouthSide.add(resetButton, BorderLayout.WEST);
rightSouthSide.add(enterButton, BorderLayout.EAST);
rightSide.add(rightNorthSide, BorderLayout.NORTH);
rightSide.add(rightSouthSide, BorderLayout.SOUTH);
frame.add(rightSide, BorderLayout.EAST);
// JPanel Center - the center of the program
JPanel center = new JPanel();
JPanel centerNorth = new JPanel();
centerNorth.add(questionDisplay, BorderLayout.NORTH);
centerNorth.add(actionDisplay, BorderLayout.SOUTH);
JPanel centerSouth = new JPanel();
JPanel centerSouthNorth = new JPanel();
centerSouthNorth.add(dealerCardText, BorderLayout.WEST);
centerSouthNorth.add(dealerCardDisplay, BorderLayout.EAST);
JPanel centerSouthSouth = new JPanel();
JPanel centerSouthSouthWest = new JPanel();
centerSouthSouthWest.add(handOneText, BorderLayout.NORTH);
centerSouthSouthWest.add(handOneDisplay, BorderLayout.SOUTH);
JPanel centerSouthSouthEast = new JPanel();
centerSouthSouthEast.add(handTwoText, BorderLayout.NORTH);
centerSouthSouthEast.add(handTwoDisplay, BorderLayout.SOUTH);
centerSouthSouth.add(centerSouthSouthWest, BorderLayout.WEST);
centerSouthSouth.add(centerSouthSouthEast, BorderLayout.EAST);
centerSouth.add(centerSouthNorth, BorderLayout.NORTH);
centerSouth.add(centerSouthSouth, BorderLayout.SOUTH);
center.add(centerNorth, BorderLayout.NORTH);
center.add(centerSouth, BorderLayout.SOUTH);
frame.add(center, BorderLayout.CENTER);
// JPanel left - the center of the program
JPanel left = new JPanel();
JPanel leftNorth = new JPanel();
JPanel leftNorthNorth = new JPanel();
JPanel leftNorthSouth = new JPanel();
JPanel leftSouth = new JPanel();
JPanel leftSouthNorth = new JPanel();
JPanel leftSouthSouth = new JPanel();
leftNorthNorth.add(standButton, BorderLayout.WEST);
leftNorthNorth.add(hitButton, BorderLayout.EAST);
leftNorthSouth.add(doubleButton, BorderLayout.WEST);
leftNorthSouth.add(splitButton, BorderLayout.EAST);
leftNorth.add(leftNorthNorth, BorderLayout.NORTH);
leftNorth.add(leftNorthSouth, BorderLayout.SOUTH);
leftSouthNorth.add(statsText, BorderLayout.WEST);
leftSouthNorth.add(statsDisplay, BorderLayout.EAST);
leftSouthSouth.add(winButton, BorderLayout.WEST);
leftSouthSouth.add(loseButton, BorderLayout.EAST);
leftSouth.add(leftSouthNorth, BorderLayout.NORTH);
leftSouth.add(leftSouthSouth, BorderLayout.SOUTH);
left.add(leftNorth, BorderLayout.NORTH);
left.add(leftSouth, BorderLayout.SOUTH);
frame.add(left, BorderLayout.WEST);
frame.setSize(1600, 200);
frame.setVisible(true);
frame.setResizable(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}