欢迎来到天天文库
浏览记录
ID:39885730
大小:98.00 KB
页数:18页
时间:2019-07-14
《Java五子棋程序》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、//Java编程:五子棋游戏源代码importjava.awt.*;importjava.awt.event.*;importjava.applet.*;importjavax.swing.*;importjava.io.PrintStream;importjavax.swing.JComponent;importjavax.swing.JPanel;/**main方法创建了ChessFrame类的一个实例对象(cf),*并启动屏幕显示显示该实例对象。**/publicclassFiveChessAppletDemo{publicstaticvoidmai
2、n(Stringargs[]){ChessFramecf=newChessFrame();cf.show();}}/**类ChessFrame主要功能是创建五子棋游戏主窗体和菜单**/classChessFrameextendsJFrameimplementsActionListener{privateString[]strsize={"20x15","30x20","40x30"};privateString[]strmode={"人机对弈","人人对弈"};publicstaticbooleaniscomputer=true,checkcomputer
3、=true;privateintwidth,height;privateChessModelcm;privateMainPanelmp;//构造五子棋游戏的主窗体publicChessFrame(){this.setTitle("五子棋游戏");cm=newChessModel(1);mp=newMainPanel(cm);Containercon=this.getContentPane();con.add(mp,"Center");this.setResizable(false);this.addWindowListener(newChessWindow
4、Event());MapSize(20,15);JMenuBarmbar=newJMenuBar();this.setJMenuBar(mbar);JMenugameMenu=newJMenu("游戏");mbar.add(makeMenu(gameMenu,newObject[]{"开局","棋盘","模式",null,"退出"},this));JMenulookMenu=newJMenu("视图");mbar.add(makeMenu(lookMenu,newObject[]{"Metal","Motif","Windows"},this));JMen
5、uhelpMenu=newJMenu("帮助");mbar.add(makeMenu(helpMenu,newObject[]{"关于"},this));}//构造五子棋游戏的主菜单publicJMenumakeMenu(Objectparent,Objectitems[],Objecttarget){JMenum=null;if(parentinstanceofJMenu)m=(JMenu)parent;elseif(parentinstanceofString)m=newJMenu((String)parent);elsereturnnull;for(
6、inti=0;i7、jm.add(rmenu);group.add(rmenu);}m.add(jm);}elseif(items[i]=="模式"){JMenujm=newJMenu("模式");ButtonGroupgroup=newButtonGroup();JRadioButtonMenuItemrmenu;for(inth=0;h8、p.add(rmenu);}m.add(jm);}elsem.ad
7、jm.add(rmenu);group.add(rmenu);}m.add(jm);}elseif(items[i]=="模式"){JMenujm=newJMenu("模式");ButtonGroupgroup=newButtonGroup();JRadioButtonMenuItemrmenu;for(inth=0;h8、p.add(rmenu);}m.add(jm);}elsem.ad
8、p.add(rmenu);}m.add(jm);}elsem.ad
此文档下载收益归作者所有