欢迎来到天天文库
浏览记录
ID:38163642
大小:18.98 KB
页数:16页
时间:2019-06-06
《java 初学者联系代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、packagemySelf;importjava.awt.Color;importjava.awt.Container;importjava.awt.Dimension;importjava.awt.GridLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.MouseAdapter;importjava.awt.event.MouseEvent;importjavax.swing.JButt
2、on;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JOptionPane;importjavax.swing.JPanel;/***练习代码规范**@author王毅臣**/publicclassCheckMineSweeping{privateintnumber=40;//设置地雷的个数privateint[]num;//存放地雷的位置privateintintx=10,inty=10;//显示多少行列privatechar[]ch;//存
3、放标签中所有要显示的字符privateinttemp=0;//临时变量privateJFramejf=null;privateContainercon=null;privateJPaneljp=null;privateJButton[]jbs;privateJLabel[]jls;privateJPanel[]jps;publicCheckMineSweeping(){ch=newchar[intx*inty];num=newint[number];jbs=newJButton[intx*inty];jls=newJLabel[in
4、tx*inty];jps=newJPanel[intx*inty];//首先初始化数组intj=0;while(true){if(j==number){//循环结束条件break;}temp=(int)(Math.random()*(intx*inty));//随即生成正整数booleanflag=false;//判断是否重复的变量for(inti=0;i5、(inti=0;i6、s.getChar(temp);}}elseif(i==intx){//说明是右上角的格子temp=0;temp+=ch[i-1]=='⊙'?1:0;//左边temp+=ch[i+intx]=='⊙'?1:0;//下边temp+=ch[i+intx+1]=='⊙'?1:0;//左下边if(temp==0){ch[i]='';}else{ch[i]=this.getChar(temp);}}elseif(i==(intx-1)*inty){//左下面temp=0;temp+=ch[i+1]=='⊙'?1:0;//右边temp+=ch[7、i-intx]=='⊙'?1:0;//上边temp+=ch[i+1-intx]=='⊙'?1:0;//右上边if(temp==0){ch[i]='';}else{ch[i]=this.getChar(temp);}}elseif(i==intx*inty-1){//右下面temp=0;temp+=ch[i-1]=='⊙'?1:0;//左边temp+=ch[i-intx]=='⊙'?1:0;//上边temp+=ch[i-intx-1]=='⊙'?1:0;//右上边if(temp==0){ch[i]='';}else{ch[i]=thi8、s.getChar(temp);}}elseif(i
5、(inti=0;i6、s.getChar(temp);}}elseif(i==intx){//说明是右上角的格子temp=0;temp+=ch[i-1]=='⊙'?1:0;//左边temp+=ch[i+intx]=='⊙'?1:0;//下边temp+=ch[i+intx+1]=='⊙'?1:0;//左下边if(temp==0){ch[i]='';}else{ch[i]=this.getChar(temp);}}elseif(i==(intx-1)*inty){//左下面temp=0;temp+=ch[i+1]=='⊙'?1:0;//右边temp+=ch[7、i-intx]=='⊙'?1:0;//上边temp+=ch[i+1-intx]=='⊙'?1:0;//右上边if(temp==0){ch[i]='';}else{ch[i]=this.getChar(temp);}}elseif(i==intx*inty-1){//右下面temp=0;temp+=ch[i-1]=='⊙'?1:0;//左边temp+=ch[i-intx]=='⊙'?1:0;//上边temp+=ch[i-intx-1]=='⊙'?1:0;//右上边if(temp==0){ch[i]='';}else{ch[i]=thi8、s.getChar(temp);}}elseif(i
6、s.getChar(temp);}}elseif(i==intx){//说明是右上角的格子temp=0;temp+=ch[i-1]=='⊙'?1:0;//左边temp+=ch[i+intx]=='⊙'?1:0;//下边temp+=ch[i+intx+1]=='⊙'?1:0;//左下边if(temp==0){ch[i]='';}else{ch[i]=this.getChar(temp);}}elseif(i==(intx-1)*inty){//左下面temp=0;temp+=ch[i+1]=='⊙'?1:0;//右边temp+=ch[
7、i-intx]=='⊙'?1:0;//上边temp+=ch[i+1-intx]=='⊙'?1:0;//右上边if(temp==0){ch[i]='';}else{ch[i]=this.getChar(temp);}}elseif(i==intx*inty-1){//右下面temp=0;temp+=ch[i-1]=='⊙'?1:0;//左边temp+=ch[i-intx]=='⊙'?1:0;//上边temp+=ch[i-intx-1]=='⊙'?1:0;//右上边if(temp==0){ch[i]='';}else{ch[i]=thi
8、s.getChar(temp);}}elseif(i
此文档下载收益归作者所有