连接四个Java游戏项目,需要基本概念方面的帮助

连接四个Java游戏项目,需要基本概念方面的帮助,java,class,user-interface,arraylist,connect,Java,Class,User Interface,Arraylist,Connect,我在实验室工作,这是一个连接四个游戏。我在一些基本概念上遇到了问题,比如类如何相互通信、如何使用私有实例变量、如何使用ArrayList、如何比较JLabel或将它们设置为可比较的东西 为了给一个简单的分类,我有四个类GUI,游戏,玩家,名字 我可以使用两个四循环来创建GUI,游戏是一个网格,有7列6块。作品是图像 JLabel Piece = new JLabel("images/blank.png"); 例如,表示一个空白点 GUI基于JFrame、单个内容窗格和四个面板,一个用于标题,指

我在实验室工作,这是一个连接四个游戏。我在一些基本概念上遇到了问题,比如类如何相互通信、如何使用私有实例变量、如何使用ArrayList、如何比较JLabel或将它们设置为可比较的东西

为了给一个简单的分类,我有四个类GUI,游戏,玩家,名字

我可以使用两个四循环来创建GUI,游戏是一个网格,有7列6块。作品是图像

JLabel Piece = new JLabel("images/blank.png");
例如,表示一个空白点

GUI基于JFrame、单个内容窗格和四个面板,一个用于标题,指示谁在玩,谁赢,另一个用于7行中的7个按钮,网格本身显示可能要玩的位置,然后是一个按钮面板,该面板提供重放选项

我缺乏很多概念。例如,重播按钮在游戏结束前不应出现

我不知道如何使用ArrayList。我试着用

ArrayList<ArrayList<JLabel>> myList = new ArrayList<ArrayList<JLabel>>(); 
得到一个特定的片段

我不知道如何将其传递给参数,例如,如果我按下第7列的按钮7,但尚未播放任何曲目,我可以从最低区域第7列第6行开始,并将其更新为播放的曲目,对于适当的播放器为红色或黄色

这是含糊不清的,我怀疑我能到达任何地方,但我迫切需要帮助。助教/老师没有太多的时间,我相信我没有足够的时间来完成这个项目

我明白它是如何工作的/我必须在文字上做什么,但在应用Java代码方面。。。
我非常感谢你的帮助

确定首先,您应该使用枚举数组。ArrayList用于许多项目,这些项目的编号可能会快速变化。数组用于在某种网格中存储数据。因为您使用的是静态板,所以请使用阵列!它们的内存占用也小得多。例如:

//Note you should use [column][row] as that is common practice.
States[][] grid = new States[7][6];
//And initialize it:
for(int i = 0; i < grid.length; i++)
    for(int o = 0; o < grid[i].length; o++)
        grid[i][o] = EMPTY_JLABEL;
在GUI中,有一个仅在游戏结束时添加到框架中的JButton。还添加一个按钮,指示玩家单击每列的时间

JButton button = new JButton();
//Initialize JButton and add to frame...

//Anytime before the frame is set to visible:
button.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        /* Perform tests for for what should happen.
           For example test whose turn it is then call a method to add a piece to that column.  Then call a checker to see if someone has won.  If so, display the replay button, otherwise do nothing (allow other player to move).
        */
    }
}

听起来你可能想和助教/教授谈谈。它们可能是比我们更好的学习Java基础知识的资源。另一个查找特定类信息的好地方是“您能用一行文字概括您的问题吗?”阅读我的文章,了解Swing应用程序是如何组合在一起的,以及类之间是如何通信的。
//Note you should use [column][row] as that is common practice.
States[][] grid = new States[7][6];
//And initialize it:
for(int i = 0; i < grid.length; i++)
    for(int o = 0; o < grid[i].length; o++)
        grid[i][o] = EMPTY_JLABEL;
public enum States {
    FULL_PLAYER_ONE(FULL_PLAYER_ONE_JLABEL), FULL_PLAYER_TWO(FULL_PLAYER_TWO_JLABEL), EMPTY(EMPTY_JLABEL);

    //The image of the appropriate state.
    private JLabel label;

    //Enum constructors must be private
    private States(JLabel label) {
        this.label = label;
    }

    public JLabel getLabel() {
        return label;
    }
}
JButton button = new JButton();
//Initialize JButton and add to frame...

//Anytime before the frame is set to visible:
button.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        /* Perform tests for for what should happen.
           For example test whose turn it is then call a method to add a piece to that column.  Then call a checker to see if someone has won.  If so, display the replay button, otherwise do nothing (allow other player to move).
        */
    }
}