java课程设计(个人)--五子棋

1.团队课程设计博客链接

http://www.cnblogs.com/mz201521044152/p/7065575.html

2.个人负责模块说明

棋盘类,绘制棋盘,绘制棋子,按钮设置,鼠标监听事件设计;

3.个人代码提交记录

4.自己负责模块或任务详细说明

//棋盘类
public class Form1 extends Panel implements MouseListener,ActionListener{

private JMenuItem startMenuItem, exitMenuItem, backMenuItem,BlackMenuItem,WhiteMenuItem;
private JButton startButton, backButton, exitButton,BlackButton,WhiteButton;
private static final int line = 15;//列数
private static final int row = 15;//行数
private static final int gap = 40;//间距
private static boolean isBlack = true;
int chessCount; // 当前棋盘的棋子个数
public static int click_X;//当前下棋子的索引
private static int click_Y;

private char[][] Chess= new char[15][15];
//Point[] chessList = new Point[17 * 17]; // 初始每个数组元素为null
private List<Integer> listX = new ArrayList<Integer>();
 private List<Integer> listY = new ArrayList<Integer>();

public Form1(){
	super();
	for(int i=0;i<Chess.length;i++){
		for(int j=0;j<Chess[i].length;j++){
			Chess[i][j]='0';
		}
	}
}
 //画棋盘网格绘制 
public void paint(Graphics g){
	
	
	//int intGame_Start=0;//游戏开始标志 0未开始 1游戏中	
	
	for(int i=0;i<row;i++){//划横线
		g.setColor(Color.BLACK);
		g.drawLine(20, 20+i*gap, 580, 20+i*gap);
	}
	for(int i=0;i<line;i++){//划纵线
		g.setColor(Color.BLACK);
		g.drawLine(20+i*gap, 20, 20+i*gap,580);
	}
	startButton = new JButton("重新开始");//三个按钮初始化
    backButton = new JButton("悔棋");
    exitButton = new JButton("退出");
	BlackButton=new JButton("黑棋");
	WhiteButton=new JButton("白棋");
	//形成开始,悔棋,推出的图形框
	setLayout(null);    
	//addActionListener(this); 
	add(startButton);    
	startButton.setBounds(650,80,80,50);   
	startButton.addActionListener(new ActionListener(){
		
		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			restartGame();
		}
		
	});   

5.课程设计感想

有很多netBeans里的方法和定义都还没有弄懂,后来网上搜资料,百度一些关于javanetbeans的使用才慢慢学会了很多,比如鼠标监听,设置按钮等;这次本来准备把联机对战的代码写出来的,由于自身知识掌握不多,还是很遗憾,以后要继续努力。
posted @ 2017-06-22 22:05  毛卓  阅读(295)  评论(0编辑  收藏  举报