资源简介
JavaSE 实现的简单版五子棋
使用JPanel的画板画棋盘跟棋子
可以存盘和复盘(文件读写)
代码片段和文件信息
package application;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.WindowConstants;
import javax.swing.Jframe;
/**
* @author Kevin
*
*/
public class FiveStep extends javax.swing.JPanel implements ActionListener {
private static final long serialVersionUID = 7315011316877886035L;
public static final int size = 15;
public static final int chessPieceSize = 40;
public static final int boardBound = 10;
private int labelHeight = 20;
private int width;
private int length;
private JLabel promptLab;
private int[][] pieces;
private int currentPieceX;
private int currentPieceY;
private boolean blackOrWhite;
private Jframe frame;
// menu bar menus and menu items
private JMenuBar menuBar;
private JMenu[] menus;
private JMenuItem[][] menuItems;
public static void main(String[] args) {
Jframe frame = new Jframe();
frame.getContentPane().add(new FiveStep(frame));
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
public FiveStep() {
super();
initGUI();
}
public FiveStep(Jframe j) {
this();
this.frame = j;
this.frame.setJMenuBar(this.menuBar);
}
private void initGUI() {
// generate the width and length
this.length = FiveStep.size * FiveStep.chessPieceSize
+ (FiveStep.boardBound * 2) + this.labelHeight;
this.width = FiveStep.size * FiveStep.chessPieceSize
+ (FiveStep.boardBound * 2);
try {
setPreferredSize(new Dimension(this.width this.length));
} catch (Exception e) {
e.printStackTrace();
}
this.promptLab = new JLabel();
this.add(this.promptLab);
// build pieces
this.pieces = new int[FiveStep.size][FiveStep.size];
for (int i = 0; i < this.pieces.length; i++) {
for (int j = 0; j < this.pieces[i].length; j++) {
this.pieces[i][j] = 0;
}
}
// initial the current x and y
this.currentPieceX = 0;
this.currentPieceY = 0;
// the black first
this.blackOrWhite = true;
// add event handle
this.eventHandle();
// set the board color
this.setBackground(Color.orange);
// set the label prompt the black first
this.promptLab.setText(“The black first“);
// build menu bar
this.menuBar = new JMenuBar();
this.menus = new JMenu[1];
this.menus[0] = new JMenu(“Game“);
this.menuItems = new JMenuItem[1][];
this.menuItems[0] = new JMenuItem[4];
this.menuItems[0][0] = new JMenuItem(“New Game“);
this.menuItems[0][1] = new JMenuItem(“Save...“);
- 上一篇:遗传算法 tsp java
- 下一篇:Java实现的打字游戏
相关资源
- 微博系统(Java源码,servlet+jsp),适
- java串口通信全套完整代码-导入eclip
- jsonarray所必需的6个jar包.rar
- 三角网构TIN生成算法,Java语言实现
- java代码编写将excel数据导入到mysql数据
- Java写的cmm词法分析器源代码及javacc学
- JAVA JSP公司财务管理系统 源代码 论文
- JSP+MYSQL旅行社管理信息系统
- 推荐算法的JAVA实现
- 基于Java的酒店管理系统源码(毕业设
- java-图片识别 图片比较
- android毕业设计
- java23种设计模式+23个实例demo
- java Socket发送/接受报文
- JAVA828436
- java界面美化 提供多套皮肤直接使用
- 在线聊天系统(java代码)
- 基于Java的图书管理系统807185
- java中实现将页面数据导入Excel中
- java 企业销售管理系统
- java做的聊天系统(包括正规课程设计
- Java编写的qq聊天室
- 商店商品管理系统 JAVA写的 有界面
- JAVA开发聊天室程序
- 在linux系统下用java执行系统命令实例
- java期末考试试题两套(答案) 选择(
- JAVA3D编程示例(建模、交互)
- Java 文件加密传输
- java做的房产管理系统
- 基于jsp的bbs论坛 非常详细
评论
共有 条评论