Java 实训论文石超.docx
- 文档编号:13933571
- 上传时间:2023-06-19
- 格式:DOCX
- 页数:28
- 大小:208.29KB
Java 实训论文石超.docx
《Java 实训论文石超.docx》由会员分享,可在线阅读,更多相关《Java 实训论文石超.docx(28页珍藏版)》请在冰点文库上搜索。
Java实训论文石超
JIANGXIAGRICULTURALUNIVERSITY
JAVA课程设计
题目:
五子棋游戏—SC加强版
学院:
软件学院
姓名:
石超
学号:
20132314
专业:
3G移动互联
班级:
1305班
指导教师:
姜允志职称:
讲师
二0一四年十二月
3.1:
主游戏界面的设计
3.2.游戏界面的布局
3.3:
启动时间显示模块
3.4:
黑白子先手选择模块
3.5:
棋盘颜色选择模块
3.6:
作者寄语响应模块
3.7:
显示当前系统时间模块(年,月,日);
3.8:
嵌入扫雷游戏模块
3.8.1:
扫雷游戏界面;
3.8.2:
扫雷游戏运行时简单介绍:
3.9:
记事本兼阅读器模块介绍:
四、本设计改进和建议
五、总结(感想和心得等)
一:
设计目的:
通过选择《Java课程设计(第二版)》通过视频学习,以及个人学习总结及摸索,选择五子棋游戏这个综合性的题目作为本次的课程设计。
可以让我们更加熟悉Java程序设计这门课程,学会熟练使用Eclipse这个软件,加深对Java语言的掌握,提高编程水平。
同时培养独立思考和同学间团结合作的能力,为毕业设计以及将来的工作打下坚实的基础。
二:
设计要求和设计指标:
参考视频教材初步学习小型java项目的构建经验,通过学习经验的总结,以及个人想法的加入,在五子棋的基础上,嵌入扫雷游戏,以及加入棋盘变换颜色以及查看时间和界面下方加入记事本的方式增加由此的趣味性以及可玩度。
三:
设计内容:
3.1:
游戏主界面的设计:
(运行图)
代码:
importjava.awt.Checkbox;
importjava.awt.CheckboxGroup;
importjava.awt.Color;
importjava.awt.Font;
importjava.awt.Graphics;
importjava.awt.Window;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.awt.event.ItemEvent;
importjava.awt.event.ItemListener;
importjava.awt.event.MouseEvent;
importjava.awt.event.MouseListener;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileWriter;
importjava.util.Date;
importjavax.accessibility.AccessibleContext;
importjavax.swing.JButton;
importjavax.swing.JFileChooser;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JOptionPane;
importjavax.swing.JPanel;
importjavax.swing.JTextArea;
importjavax.swing.plaf.PanelUI;
importjava.awt.event.*;
importjava.awt.*;
importjavax.swing.*;
importjavax.swing.border.*;
importjava.util.*;
importjava.io.*;
importjavax.swing.KeyStroke;
importjava.awt.event.KeyEvent;
publicclassFivCheseextendsJFrame{
CheseGameCG;
FivChese()
{
this.CG=newCheseGame();
addMouseListener(CG);
add(CG);
}
publicstaticvoidmain(String[]args){
FivChesefivechese=newFivChese();
fivechese.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fivechese.setSize(900,700);
fivechese.setTitle("五子棋by-石超");
fivechese.setVisible(true);
fivechese.setResizable(true);
}
}
3.2游戏界面布局
(运行图)
代码:
JLabell=newJLabel("亲运行游戏的时间:
"+newDate());
//l.setText("当前时间为"+newDate());
JLabelk=newJLabel("亲下面是一个记事本兼阅读器:
");
JLabelb=newJLabel("步数:
");
JButtonbtn1=newJButton("开始游戏!
");//游戏开始
JButtonbtn2=newJButton("重新开始!
");//游戏重置
JButtonbtn3=newJButton("退出游戏:
");
JButtonbtn4=newJButton("作者寄语");
JButtonbtn5=newJButton("玩会扫雷");
JButtonbtn6=newJButton("现在时间");
//确定白棋先还是黑棋先
CheckboxGroupcbg=newCheckboxGroup();
Checkboxchb1=newCheckbox("黑棋先手",cbg,true);
Checkboxchb2=newCheckbox("白棋先手",cbg,false);
CheckboxGroupcg=newCheckboxGroup();
Checkboxcb1=newCheckbox("绿色:
",cg,true);
Checkboxcb2=newCheckbox("兰色:
",cg,false);
3.3启动时间显示模块:
(运行图)
代码:
JLabell=newJLabel("亲运行游戏的时间:
"+newDate());
3.4:
黑白棋先手选择模块:
(运行图)
代码:
//确定白棋先还是黑棋先
CheckboxGroupcbg=newCheckboxGroup();
Checkboxchb1=newCheckbox("黑棋先手",cbg,true);
Checkboxchb2=newCheckbox("白棋先手",cbg,false);
3.5棋盘颜色选择模块:
(运行图)
代码:
CheckboxGroupcg=newCheckboxGroup();
Checkboxcb1=newCheckbox("绿色:
",cg,true);
Checkboxcb2=newCheckbox("兰色:
",cg,false);
3.6:
作者寄语响应模块
(运行图)
代码
packagescsc;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JTextArea;
publicclassjyextendsJFrameimplementsActionListener{
JTextAreata;
JButtonbtn;
jy(){
this.setSize(400,300);
this.setTitle("作者寄语");
this.setLayout(null);
ta=newJTextArea("这是一个集五子棋,扫雷,两个游戏于一体的游戏,具体功能还有:
1:
依照玩家喜好选择棋盘颜色,2:
有一个记事本兼阅读器界面边玩游戏边阅读记入,3:
通过转换按钮选择扫雷4:
通过时间查看按钮查看当前时间.更多功能玩家们自己去探索吧!
这个游戏是本人原创经过多天努力,用度娘和自己探索一步步把遇到的问题一点点的解决了,但还是留有一些自己解决不了的难题,所以整个游戏还是不够完美,希望玩家不要介意哈,本人已经尽全力了哈!
-----------作者:
石超");
ta.setEditable(false);
ta.setLineWrap(true);
ta.setBounds(0,0,400,250);
btn=newJButton("返回");
btn.setBounds(150,250,100,20);
btn.addActionListener(this);
this.add(ta);
this.add(btn);
this.setVisible(true);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
publicstaticvoidmain(String[]args){
newjy();
}
@Override
publicvoidactionPerformed(ActionEvente){
if(e.getSource()==btn){
this.dispose();
newFivChese();
}
//TODO自动生成的方法存根
}
}
3.7:
显示当前系统时间模块:
(运行图)
代码:
packagescsc;
importjava.awt.*;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.awt.event.MouseEvent;
importjava.awt.event.MouseListener;
importjava.io.BufferedReader;
importjava.io.BufferedWriter;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileNotFoundException;
importjava.io.FileOutputStream;
importjava.io.IOException;
importjava.io.InputStreamReader;
importjava.io.OutputStreamWriter;
//importjava.sql.Date;
importjava.text.DateFormat;
importjava.text.SimpleDateFormat;
importjava.util.Calendar;
importjava.util.Date;
importjavax.swing.JButton;
importjavax.swing.JDialog;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JOptionPane;
importjavax.swing.JPanel;
importjavax.swing.JScrollPane;
importjavax.swing.JTable;
importjavax.swing.JTextArea;
importjavax.swing.JTextField;
importjavax.swing.table.DefaultTableModel;
publicclasswannianliextendsJFrameimplementsActionListener,MouseListener
{
privateCalendarcld=Calendar.getInstance();
privateString[]astr={"星期一","星期二","星期三","星期四","星期五","星期六","星期日"};
privateDefaultTableModeldtm=newDefaultTableModel(null,astr);
privateJTabletable=newJTable(dtm);//装日期的表格
privateJScrollPanesp=newJScrollPane(table);
privateJButtonbLastYear=newJButton("上一年");
privateJButtonbNextYear=newJButton("下一年");
privateJButtonbLastMonth=newJButton("上月");
privateJButtonbNextMonth=newJButton("下月");
privateJTextFieldjtfYear=newJTextField(5);//jtfYear年份显示和输入文本框
privateJTextFieldjtfMonth=newJTextField
(2);//jtfMonth月份显示文本框
privateJPanelp1=newJPanel();//装入控制日期按钮的模块
privateJPanelp2=newJPanel();
privateJPanelp3=newJPanel(newBorderLayout());
privateJPanelp4=newJPanel(newGridLayout(2,1));
privateJPanelp5=newJPanel(newBorderLayout());
privateJButtonbAdd=newJButton("保存日志");
privateJButtonbDel=newJButton("返回");
privateJTextAreajta=newJTextArea();//jta--JTextArea
privateJScrollPanejsp=newJScrollPane(jta);
privateJLabell=newJLabel("年份文本框中可直接键入要查找的年份,以提高查询效率");
privateJLabellt=newJLabel();
privateJLabelld=newJLabel();
privateintlastTime;
publicwannianli()
{
super("万年历");//框架命名
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);//窗口关闭函数
this.getContentPane().setLayout(newBorderLayout(10,0));
jta.setLineWrap(true);
table.setGridColor(Color.GRAY);//星期之间的网格线是灰色的
table.setColumnSelectionAllowed(true);
table.setSelectionBackground(Color.BLACK);//当选定某一天时这一天背景黑色
table.setSelectionForeground(Color.GREEN);//选定的日期字体是绿色的
table.setBackground(newColor(184,207,229));//日期显示表格颜色浅蓝色
table.setFont(newFont("黑体",Font.BOLD,24));//日期数字字体格式
table.setRowHeight(30);//表格的高度
table.addMouseListener(this);//鼠标监听器
jtfYear.addActionListener(this);//可输入年份的文本框
//为各个按钮添加监听函数
bAdd.addActionListener(this);
bDel.addActionListener(this);
bLastYear.addActionListener(this);
bNextYear.addActionListener(this);
bLastMonth.addActionListener(this);
bNextMonth.addActionListener(this);
//将按钮添加到Jpanel上
p1.add(bLastYear);
p1.add(jtfYear);//年份输入文本框
p1.add(bNextYear);
p1.add(bLastMonth);
p1.add(jtfMonth);
p1.add(bNextMonth);
p2.add(bAdd);
p2.add(bDel);
p3.add(jsp,BorderLayout.CENTER);
p3.add(p2,BorderLayout.SOUTH);
p3.add(ld,BorderLayout.NORTH);
p4.add(l);
p4.add(lt);
p5.add(p4,BorderLayout.SOUTH);
p5.add(sp,BorderLayout.CENTER);
p5.add(p1,BorderLayout.NORTH);
this.getContentPane().add(p5,BorderLayout.CENTER);
this.getContentPane().add(p3,BorderLayout.EAST);
String[]strDate=DateFormat.getDateInstance().format(newDate()).split("-");//获得日期
cld.set(Integer.parseInt(strDate[0]),Integer.parseInt(strDate[1])-1,0);
showCalendar(Integer.parseInt(strDate[0]),Integer.parseInt(strDate[1]),cld);
jtfMonth.setEditable(false);//设置月份的文本框为不可编辑
jtfYear.setText(strDate[0]);
jtfMonth.setText(strDate[1]);
this.showTextArea(strDate[2]);
ld.setFont(newFont("新宋体",Font.BOLD,24));
newTime(lt).start();
this.setBounds(200,200,600,320);
this.setResizable(false);
this.setVisible(true);
}
publicvoidshowCalendar(intlocalYear,intlocalMonth,Calendarcld)
{
intDays=getDaysOfMonth(localYear,localMonth)+cld.get(Calendar.DAY_OF_WEEK)-2;
Object[]ai=newObject[7];
lastTime=0;
for(inti=cld.get(Calendar.DAY_OF_WEEK)-1;i<=Days;i++)
{
ai[i%7]=String.valueOf(i-(cld.get(Calendar.DAY_OF_WEEK)-2));
if(i%7==6)
{
dtm.addRow(ai);
ai=newObject[7];
lastTime++;
}
}
dtm.addRow(ai);
}
publicintgetDaysOfMonth(intyear,intMonth)//显示所选月份的天数
{
if(Month==1||Month==3||Month==5||Month==7||Month==8||Month==10||Month==12)
{
return31;
}
if(Month==4||Month==6||Month==9||Month==11)
{
return30;
}
if(year%4==0&&year%100!
=0||year%400==0)//闰年
{
return29;
}
else
{
return28;
}
}
publicvoidactionPerformed(ActionEvente)
{
if(e.getSource()==jtfYear||e.getSource()==bLastYear||e.getSource()==bNextYear||
e.getSource()==bLastMonth||e.getSource()==bNextMonth)
{
intm,y;
try//控制输入的年份正确,异常控制
{
if(jtfYear.getText().length()!
=4)
{
thrownewNumberFormatException();
}
y=Integer.parseInt(jtfYear.getText());
m=Integer.pars
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 实训论文石超 论文
![提示](https://static.bingdoc.com/images/bang_tan.gif)