我正在制作一个得分保持计划,但我遇到了一个问题.我试图做的是在顶部有一个包含两个JPanel的JPanel,而JPanel又包含两个团队名称.我很困惑为什么程序顶部的两个JLabel没有集中在它们所包含的JPanels中.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ScoreFrame extends JFrame {
private static final Dimension SCREEN_SIZE = Toolkit.getDefaultToolkit().getScreenSize();
private static final int WIDTH = SCREEN_SIZE.width;
private static final int HEIGHT = SCREEN_SIZE.height;
private final JTextField[] nameField = new JTextField[] { new JTextField(),new JTextField() };
private final JLabel[] nameLabel = new JLabel[] { new JLabel("Team 1"),new JLabel("Team 2") };
private final GridBagLayout gridBag = new GridBagLayout();
private final GridBagConstraints constraints = new GridBagConstraints();
private final JPanel topPanel = new JPanel();
public Sc