資源簡介
內容索引:JAVA源碼,游戲娛樂,五子棋
基于GUI的Java五子棋游戲源碼,可人機對戰,用java swing做的,運行時需要修改圖片的路徑。
制作思路:
用按鈕做棋子,用圖片填充每個按鈕。
設置棋盤為24*24的,五子棋FiveChessGame類,繼承了JFrame,并且添加了時間監聽,五子棋的棋子chess,用JButton表示,五子棋棋子chess對應的棋子標識,用于標記棋子的狀態。 1表示黑棋,-1表示白棋,默認0表示無棋子,點擊棋子時設置棋子的圖標setOnChessIcon。 根據判斷該位置的棋子是否有棋子,和棋子顏色設置棋子圖標
測試棋子的方法showChess。用于將chessInt數組內容打印到控制臺,以便觀看。

代碼片段和文件信息
package?FiveChessGame;
//download?by?http://www.codefans.net
import?javax.swing.*;
import?java.awt.*;
import?java.awt.event.*;
public?class?AboutDialog?extends?JDialog?implements?ActionListener?{
private?static?final?long?serialVersionUID?=?1L;
boolean?restartflag?=?false;
public?AboutDialog(Jframe?jframe)?{
//?TODO?Auto-generated?constructor?stub
super(jframe?“關于“?true);
this.setLayout(new?GridLayout(41));
JButton?closeButton?=?new?JButton(“關閉“);
JLabel?label1?=?new?JLabel(“單機版五子棋v1.0“);
JLabel?label2=new?JLabel(“Made?by?MYlitBoY“);
JLabel?label3=new?JLabel(“Made:2010.6.7-6.86.23-6.25“);
closeButton.addActionListener(this);
closeButton.setActionCommand(“Close“);
this.add(label1);
this.add(label2);
this.add(label3);
this.add(closeButton);
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setLocation(400?350);
this.setSize(260?300);
this.pack();
this.setResizable(false);
this.setVisible(true);
}
public?boolean?getButtonPrassed()?{
return?restartflag;
}
public?void?actionPerformed(ActionEvent?arg0)?{
if?(arg0.getActionCommand()?==?“Close“)?{
this.dispose();
this.toBack();
}?
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-08-15?09:39??GUI版Java五子棋源碼,可人機對戰\
?????文件?????????562??2018-08-15?09:39??GUI版Java五子棋源碼,可人機對戰\下載說明.txt
評論
共有 條評論