一直在做一个学校项目,我和我的团队正在制作一个带有 GUI 和所有东西的财富之轮游戏。在制作要显示的拼图面板时,我遇到了创建附加列的问题。它也可能只是空的空间,但无论如何,我想知道如何摆脱它。这是letterBoard
贯穿该类的类的代码wheelGUI
。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class letterBoard extends JPanel
implements ActionListener
{
private JTextField[] fields = new JTextField[TEXT_FIELD_COUNT];
private Box[] boxes = new Box[SUIT_COUNT];
private static int TEXT_FIELD_COUNT = 14;
private static int SUIT_COUNT = 1;
Color datGreen=new Color(0, 180, 100);
public letterBoard()
{
setBackground(Color.GRAY);
JPanel panel = new JPanel(new GridLayout(4,1));
panel.setBackground(datGreen);
for(int t=0; t<4; t++)
{
for (int i =0; i < boxes.length; i++)
{
boxes[i] = Box.createHorizontalBox();
for (int j=0; j< TEXT_FIELD_COUNT/SUIT_COUNT; j++)
{
int index = i * (TEXT_FIELD_COUNT/SUIT_COUNT) + j;
fields[index] = new JTextField(" ");
fields[index].setEditable(false);
fields[index].setPreferredSize(new Dimension(50, 50));
fields[index].setBorder(BorderFactory.createLineBorder(Color.BLACK,1));
panel.add(fields[index]);
panel.add(boxes[i]);
panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLACK,3),"WHEEL OF FORTUNE"));
}
}
}
Box b1 = Box.createVerticalBox();
b1.add(panel);
b1.add(Box.createVerticalStrut(5));
b1.add(Box.createHorizontalStrut(5));
add(b1);
}
public void actionPerformed(ActionEvent e)
{
}
}
识别问题的任何帮助都会很棒。这是编译后的样子。右边的绿条是问题所在。谢谢!