for(y=0;y<length;y++){
for(x=0;x<width;x++){
grid[x][y]=new JButton(" ");
grid[x][y].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
((JButton)e.getSource()).setBorder(border);;
System.out.println("Where do you want to move this piece");
}
});
grid[x][y].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent r){
grid[x][y]=grid[x][y-1];
((JButton)r.getSource()).setBorder(border);;
System.out.println("Derp");
}
});
frame.add(grid[x][y]);
}
}
我想点击一块,然后当你点击另一个方块时,这块会向上移动一个。我知道这是错误的,我会展示合法的动作,但现在我需要让棋子移动。请帮忙!!我完全被卡住了,直到我弄清楚这一点。