*首先我的英语不好,请试着理解我。我想创建 Slide Puzzle 游戏,但我不了解滑动块的方法和单击滑动事件的方法。(我的意思是 MouseLister)现在我只有 GUI
public PGWindow() {
JFrame frame = new JFrame("SlidePuzzle");
JPanel Board = new JPanel();
Board.setLayout(new GridLayout(3, 3));
Font fn = new Font("Tahoma", Font.BOLD, 60);
int Num = 1;
for (int row = 0; row < 3; row++) {
for (int col = 0; col < 3; col++) {
if (Num == 9) {
break;
}
else {
Board.add(new JButton(String.valueOf(+Num))).setFont(fn);
}
Num++;
}
}
frame.add(Board);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 600);
frame.setLocation(600, 90);
frame.setVisible(true);
}
感谢您的帮助。