Connect4下降动画

时间:2014-02-21 11:07:30

标签: java swing animation timer jbutton

我是GUI的新手,我听说过Timer但我不确定当用户点击其中一个下拉按钮时,我将如何应用它来设置令牌的下降动作的动画小组的顶部。

截至目前我只使用setIcon()将棋盘上的一个空圈改为当前玩家的轮换颜色。

这是我的一些代码:

//1 is for green, 2 is for red
//Set icon. Know where to place first from setPosition.

public void setToken(int token, int i, int j){  
    if (token == 1){
        buttonArray[i][j].setIcon (greentoken);
        if (active == GREEN){
            active = RED;
        }else if (active == RED){
            active = GREEN;
    }
    }else if (token == 2){
        buttonArray[i][j].setIcon (redtoken);
        if (active == GREEN){
            active = RED;
        }else if (active == RED){
            active = GREEN;
        }
    }
}
//Position checker. 
//Invoked by checkColFull().
//checkColFull() called after a drop button is clicked and checks if column is full.

public void setPosition(int column){
    int row;
    for (row = 0; row < ROWS; ++row){
        if (slots[row][column] > 0)
            break;
    }
    if (row > 0){
        //save
        slots[--row][column] = active;  
        setToken(active, row, column);
    }
}
    public void actionPerformed (ActionEvent e){
    //Buttons
        else if (e.getSource () == b1){
            checkColFull (0);
        }
        else if (e.getSource () == b2){
            checkColFull(1);
        }
        else if (e.getSource () == b3){
            checkColFull(2);
        }
        else if (e.getSource () == b4){
            checkColFull(3);
        }
        else if (e.getSource () == b5){
            checkColFull(4);
        }
        else if (e.getSource () == b6){
            checkColFull (5);
        }
        else if (e.getSource () == b7){
            checkColFull(6);
        }
}

如果我提供的代码段不够,请有人告诉我。

我是否必须废弃所有内容才能实现我追求的令牌动画效果?任何提示?

0 个答案:

没有答案