java收_收java的小程序……谢谢

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

r=new JRadiobuttonMenuItem((String)item);

else if(item instanceof JRdioButtonMenuItem)

r=(JRadioButtonMenuItem)item;

else return null;

if(target instanceof ActionListener)

r.addActionListener((ActionListener)target);

return r;

}

public void MapSize(int w, int h){

setSize(w*20+5,h*20+100);

if(this.checkcomputer)

this.iscomputer=true;

else

this.iscomputer=false;

mp.setModel(cm);

mp.repaint();}

public boolean getiscomputer(){

return this.iscomputer;}

publid void restart(){

int modChess=cm.getModeChess();

if(modeChess<=3 && modChess>=1){

cm=new ChessModel(modeChess);

MapSize(cm.getWidth(),cm.getHeight());}

else{System.out.perintln("\u81EA\u5B9A\u4E49");}

}

public void actionPerformed(ActionEvent e){

String arg=e.getActionCommand();

try{

if(arg.equals("Windows"))

UIManager.setLoolAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

else if(arg.equals("Motif"))

UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");

SwingUtilities.updateConentTreeUI(this);}

catch(Exception ee){}

if(arg.equals("20*15")){

this.width=20;this.height=15;

cm=new ChessModel(1);

MapSize(this.width,this.height);

SwingUtilities.updateComponentTreeUI(this);}

if(arg.equals("40*30")){

this.width=40;

this.height=30;

cm=new ChessMOdel(3);

MapSize(this.width,this.height);

SwingUtilities.updateComponentTreeUI(this);}

if(arg.equals("人机对弈")){

this.checkcomputer=true;

this.iscomputer=true;

cm=new ChessModel(cm.getModeChess());

MapSize(this.getWidth(),this.getHeight());

SwingUtilities.updateComponentTreeUI(this);}

if(arg.equals("人人对弈")){

this.checkcomputer=false;

this.iscomputer=false;

cm=new ChessModel(cm.getModeChess());

MapSize(cm.getWidth(),cm.getHeight());

SwingUtilities.updateCopinentTreeUI(this);}

if(arg.equals("开局")){

restart();}

if(arg.equals("关于"))

JOptionpane.showMessageDialog(this,"五子棋游戏测试版","关于",0);

if(arg.equals("退出"))

System.exit(0);

}

}

class ChessModel{

private int x=0,y=0;

private int arrMapShow[][];

private boolean isOdd,isExist;

private int height;

private int widthl

ptivate int modeChess;

public ChessModel(){}

public ChessModel(int modeChess){

this.isOdd=true;

if(modechess==1){

PanelInit(20,15,modeChess);}

if(modeChess==2){

PanelInit(30,20,modeChess);}

if(modeChess==3){

PanelInit(40,30,modeChess);}}

private void PanelInit(int width,int height,int modeChess){

this.width=width;

this.height=neight;

this.modeChess=modeChess;

arrMapShow=new int[width+1][height+1];for(int i=0;i

arrMapShow[i][j]=-5;}}}

public boolean getisOdd(){

return this.isOdd;}

public void setisOdd(boolean isOdd){

if(isOdd)

this.isOdd=true;

else

this.isOdd=false;}

public boolean getisExist(){

return this.isExist;}

public int getWidth(){

return this.width;}

public int getHeight(){

return this.height;}

public int getModeChess(){

return this.modeChess;}

public int[][]getarrMapShow(){

return arrMapShow;}

private boolean badxy(int x,int y){

if(x>=width+20||x<0)

return true;

return y>=height+20 || y<0;}

public boolean chessExist(int i, int j){

if(this.arrMapShow[i][j]==1||this.arrMapShow[i][j]==2)

return true;

return false;}

public void readyplay(int x,int y){

if(badxy(x,y))

return;

if(chessExist(x,y)){

this.isExist=true;

return;}

else

this.isExist=false;

if(getisOdd()){

setisOdd(fslse);

this.arrMapShow[x][y]=1;}

else{

setisOdd(true);

this.arrMapShow[x][y]=2;}}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值