خرید بک لینک

Vote count: 0

I'm begier in java-swing. I try to make some desk game. I got 2 packages (one representing game[with classes Game, Players] and the other representing [with classes Board, BoardField, BorderField and Disk] ... there are some interfaces yet, which is not important for my question. What I'm trying to do is coect the logical layer of Board and GUI, I'm totally newbie and can't find any tutorial where this is solved. I post here some pieces of my code for you to know what it looks like

public class Board extends java.lang.Object{

    private final int size;
    private final Field [][] fields;


    public Board(int size){  
        this.size = size;
        this.fields = new Field [size][size];
        for (int i = 0; i < size; i++){
            for (int j = 0; j < size; j++){
                if ((i == 0) || (i == size - 1) || (j == 0) || (j == size -1)){
                    this.fields [i][j] = new BorderField();  

                }
                else{ 
                    this.fields [i][j] = new BoardField (i,j);
                }
            }
        }
...

And here is my GUI try:

public void make_board(){
     JButton[][] numButton = new JButton[6][6];
    for(int i=0;i<6;i++){
    for(int j=0;j<6;j++){
    numButton[i][j] = new JButton(String.valueOf(i+j));
    getContentPane().add(numButton[i][j]);
    }

    }
}

Class Board implements board for game(it's Reversi game, you might know it). In my GUI example I use value 6 as a size of board. There are two for-loops, they go through the board and decide whether actual field is borderfield or boardfield (which is important because of rules of the game). In my GUI method make_board() I got analogy to this, I created two-dimensional array of Buttons which demonstrates fields of the game board.

ALSO, as I've told - how can i 'tell' the GUI that Buttons(in GUI) are Fields (in Board class)?

asked 48 secs ago

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 12 ارديبهشت 1395 ساعت: 7:11

صفحه بندی