版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、/*一个java围棋程序源代码*/ import java.awt.*;import java.awt.event.*;import javax.swing.joptionpane;public class chess extends frame chesspad chesspad= new chesspad(); chess() add(chesspad); chesspad.setbounds(70,90,440,440); label label=new label(click to point,doubled_click to remove,right click to back,la
2、bel.center); add(label); label.setbounds(70,55,440,24); label.setbackground(color.orange); addwindowlistener ( new windowadapter() public void windowclosing(windowevent e) system.exit(0); ); setlayout(null); setvisible(true); setsize(600,550); public static void main(string args) chess chess=new che
3、ss(); class chesspad extends panel implements mouselistener, actionlistener,focuslistener int x = -1, y = -1, chesscolor = 1; string blackname=,whitename=; button startbutton=new button(restart); button inputbutton=new button(input); textfield text_1=new textfield(black please), text_2=new textfield
4、(),/white please text_3=new textfield(blackname), text_4=new textfield(whitename); chesspad() add(inputbutton); inputbutton.setbounds(35,5,60,26); inputbutton.addactionlistener(this); inputbutton.addfocuslistener(this); add(text_3); text_3.setbounds(115,5,90,24); text_3.addfocuslistener(this); text_
5、3.seteditable(true); add(text_4); text_4.setbounds(315,5,90,24); text_4.addfocuslistener(this); text_4.seteditable(true); add(startbutton); startbutton.setbounds(35,36,60,26); startbutton.setenabled(false); startbutton.addactionlistener(this); add(text_1); text_1.setbounds(115,36,90,24); text_1.sete
6、nabled(false); text_1.seteditable(false); add(text_2); text_2.setbounds(315,36,90,24); text_2.setenabled(false); text_2.seteditable(false); setsize(440,440); setlayout(null); setbackground(color.orange); addmouselistener(this); public void paint(graphics g) for(int i=80;i=400;i=i+20) g.drawline(40,i
7、,400,i); g.drawline(40,420,400,420); for(int j=40;j=380;j=j+20) g.drawline(j,80,j,420); g.drawline(400,80,400,420); g.filloval(97,137,6,6); g.filloval(337,137,6,6); g.filloval(97,377,6,6); g.filloval(337,377,6,6); g.filloval(217,257,6,6); public void focusgained(focusevent e) component com=(componen
8、t)e.getsource(); if(com=text_3) text_3.settext(); else if(com=text_4) text_4.settext(); public void focuslost(focusevent e) public void mousepressed(mouseevent e) if(e.getmodifiers()=inputevent.button1_mask) x = (int)e.getx(); y = (int)e.gety(); int a=(x+10)/20,b=(y+10)/20; chesspoint_black chesspoi
9、nt_black=new chesspoint_black(this); chesspoint_white chesspoint_white=new chesspoint_white(this); if(x/202|y/2019|y/2020) else if(blackname.length()=0|whitename.length()=0) joptionpane.showmessagedialog(this,please input the players name,and click input button before you start chess!,reminder,jopti
10、onpane.warning_message); else if(blackname.equals(blackname) joptionpane.showmessagedialog(this,please input the black players name,and click input button,reminder,joptionpane.warning_message); else if(whitename.equals(whitename) joptionpane.showmessagedialog(this,please input the white players name
11、,and click input button,reminder,joptionpane.warning_message); else if(chesscolor=1) this.add(chesspoint_black); chesspoint_black.setbounds(a*20-10,b*20-10,20,20); chesscolor=chesscolor*(-1); text_2.settext(this.whitename+ please); text_1.settext(); else if(chesscolor=-1) this.add(chesspoint_white);
12、 chesspoint_white.setbounds(a*20-10,b*20-10,20,20); chesscolor=chesscolor*(-1); text_1.settext(this.blackname+ please); text_2.settext(); public void mousereleased(mouseevent e) public void mouseentered(mouseevent e) public void mouseexited(mouseevent e) public void mouseclicked(mouseevent e) public
13、 void actionperformed(actionevent e) if(e.getsource()=inputbutton) blackname=text_3.gettext().trim(); whitename=text_4.gettext().trim(); if(blackname.length()=0|whitename.length()=0) joptionpane.showmessagedialog(this,you did not complete the information or you have input the illegal characteristics
14、!,reminder,joptionpane.warning_message); else if(blackname.equals(blackname) joptionpane.showmessagedialog(this,please input the black players name,reminder,joptionpane.warning_message); else if(whitename.equals(whitename) joptionpane.showmessagedialog(this,please input the white players name,remind
15、er,joptionpane.warning_message); else if(text_3.gettext().equals(text_4.gettext() joptionpane.showmessagedialog(this,you have input the same name for two different players, please reinput the players name,reminder,joptionpane.warning_message); else inputbutton.setenabled(false); text_3.removefocusli
16、stener(this); text_3.setenabled(false); text_4.setenabled(false); startbutton.setenabled(true); text_1.setenabled(true); text_1.settext(blackname+ please); text_2.setenabled(true); else if(e.getsource()=startbutton) this.removeall(); inputbutton.setenabled(true); text_3.setenabled(true); text_4.sete
17、nabled(true); startbutton.setenabled(false); text_1.setenabled(false); text_2.setenabled(false); chesscolor=1; add(startbutton); startbutton.setbounds(35,36,60,26); add(text_1); text_1.setbounds(115,36,90,24); text_1.settext(black please); add(text_2); text_2.setbounds(315,36,90,24); text_2.settext(
18、); add(inputbutton); inputbutton.setbounds(35,5,60,26); add(text_3); text_3.settext(blackname); text_3.addfocuslistener(this); text_3.setbounds(115,5,90,24); add(text_4); text_4.settext(whitename); text_4.setbounds(315,5,90,24); blackname=; whitename=; class chesspoint_black extends canvas implement
19、s mouselistener chesspad chesspad=null; chesspoint_black(chesspad p) setsize(20,20); chesspad=p; addmouselistener(this); public void paint(graphics g) g.setcolor(color.black); g.filloval(0,0,20,20); public void mousepressed(mouseevent e) if(e.getmodifiers()=inputevent.button3_mask) chesspad.remove(t
20、his); chesspad.chesscolor=1; chesspad.text_2.settext(); chesspad.text_1.settext(chesspad.blackname+ please); public void mousereleased(mouseevent e) public void mouseentered(mouseevent e) public void mouseexited(mouseevent e) public void mouseclicked(mouseevent e) if(e.getclickcount()=2) chesspad.remove(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 汽车维修工岗位实践综合技能考核试卷含答案
- 墨锭制作工岗位安全教育考核试卷含答案
- 教资笔试综合试题及答案
- 高活性酵母对良凤肉种鸡生产性能及生理指标影响的探究
- 高次多项式系统定性分析:理论、方法与应用探究
- 高校设计专业色彩艺术基础教学体系的革新之路
- 高校教师心理资本的多维剖析与发展路径探究
- 高校学生评教指标体系:构建逻辑、应用策略与优化路径
- 高星级酒店建设项目投资控制策略与实践-以Y酒店为鉴
- 高新技术产业赋能浙江区域经济发展的多维审视与策略探究
- 高校设计教学课件
- 2025年古典音乐理论考试试卷及答案
- 《GIS空间分析理论与方法》课件-项目一:GIS空间分析基础
- JJG 667-2025 液体容积式流量计检定规程
- 城市建筑群基于弹塑性时程分析的震害评估标准
- 银行业金融机构安全评估标准
- 基于可得然胶改善预制卤牛肉品质特性的研究
- 2022 年全国行业职业技能竞赛- 第十一届全国民政行业职业技能竞赛 殡仪服务员项目 参考题库
- 纳税检查 第2版 郝宝爱 课程标准
- 安全生产应急预案管理办法
- 小升初奥数思维训练100题(附解析)
评论
0/150
提交评论