欢迎来到天天文库
浏览记录
ID:14326436
大小:65.50 KB
页数:26页
时间:2018-07-27
《java五子棋源代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、java五子棋源代码importjava.awt.Color;importjava.awt.Container;importjava.awt.Graphics;importjava.awt.event.*;importjava.applet.*;importjava.io.PrintStream;importjavax.swing.*;importjavax.swing.ButtonGroup;importjavax.swing.JFrame;importjavax.swing.JMenu;importjavax.swing.JMenuBar;importjavax.swing.JMenuIt
2、em;importjavax.swing.JOptionPane;importjavax.swing.JPanel;importjavax.swing.JRadioButtonMenuItem;importjavax.swing.SwingUtilities;importjavax.swing.UIManager;/**main方法创建了ChessFrame类的一个实例对象cf;*并自动屏幕显示该对象的实例*/publicclassFiveChessAppletDemo{publicstaticvoidmain(Stringargs[]){ChessFramecf=newChessFrame(
3、);cf.show();}}/**类ChessFrame主要功能是创建五子棋游戏的主窗体和菜单*/classChessFrameextendsJFrameimplementsActionListener{privateString[]strsize={"20x15","30x20","40x30"};privateString[]strmode={"人机对弈","人人对弈"};publicstaticbooleaniscomputer=true,checkcomputer=true;privateintwidth,height;privateChessModelcm;privateMainPa
4、nelmp;//构造五子棋游戏的主窗口体publicChessFrame(){this.setTitle("五子棋游戏");cm=newChessModel(1);mp=newMainPanel(cm);Containercon=this.getContentPane();con.add(mp,"Center");this.setResizable(false);this.addWindowListener(newChessWindowEvent());MapSize(20,15);JMenuBarmbar=newJMenuBar();this.setJMenuBar(mbar);JMenug
5、ameMenu=newJMenu("游戏");mbar.add(makeMenu(gameMenu,newObject[]{"开局","棋盘","模式",null,"退出"},this));JMenulookMenu=newJMenu("视图");mbar.add(makeMenu(lookMenu,newObject[]{"Metal","Motif","Windows"},this));JMenuhelpMenu=newJMenu("帮助");mbar.add(makeMenu(helpMenu,newObject[]{"关于"},this));}//构造五子棋的主菜单publicJMen
6、umakeMenu(Objectparent,Objectitems[],Objecttarget){JMenum=null;if(parentinstanceofJMenu)m=(JMenu)parent;elseif(parentinstanceofString)m=newJMenu((String)parent);elsereturnnull;for(inti=0;i7、oup=newButtonGroup();JRadioButtonMenuItemrmenu;for(intj=0;j
7、oup=newButtonGroup();JRadioButtonMenuItemrmenu;for(intj=0;j
此文档下载收益归作者所有