围棋源代码JavaApplet小程序_第1页
围棋源代码JavaApplet小程序_第2页
围棋源代码JavaApplet小程序_第3页
围棋源代码JavaApplet小程序_第4页
围棋源代码JavaApplet小程序_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论