java程序代码连连看有注释

上传人:工**** 文档编号:470058706 上传时间:2023-03-17 格式:DOC 页数:10 大小:38.51KB
返回 下载 相关 举报
java程序代码连连看有注释_第1页
第1页 / 共10页
java程序代码连连看有注释_第2页
第2页 / 共10页
java程序代码连连看有注释_第3页
第3页 / 共10页
java程序代码连连看有注释_第4页
第4页 / 共10页
java程序代码连连看有注释_第5页
第5页 / 共10页
点击查看更多>>
资源描述

《java程序代码连连看有注释》由会员分享,可在线阅读,更多相关《java程序代码连连看有注释(10页珍藏版)》请在金锄头文库上搜索。

1、/连连看java源代码mport javax.swing.*; import java.awt.*; import java.awt.event.*; public class lianliankan implements ActionListener JFrame mainFrame; /主面板 Container thisContainer; JPanel centerPanel,southPanel,northPanel; /子面板 JButton diamondsButton = new JButton65;/游戏按钮数组 JButton exitButton,resetButton,

2、newlyButton; /退出,重列,重新开始按钮 JLabel fractionLable=new JLabel(0); /分数标签 JButton firstButton,secondButton; /分别记录两次被选中的按钮 int grid = new int87;/储存游戏按钮位置 static boolean pressInformation=false; /判断是否有按钮被选中 int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; /游戏按钮的位置坐标 int i,j,k,n;/消除方法控制 public void i

3、nit() /开始方法mainFrame=new JFrame(JKJ连连看); /字符thisContainer = mainFrame.getContentPane(); thisContainer.setLayout(new BorderLayout(); centerPanel=new JPanel(); southPanel=new JPanel(); northPanel=new JPanel(); thisContainer.add(centerPanel,Center); thisContainer.add(southPanel,South); thisContainer.ad

4、d(northPanel,North); centerPanel.setLayout(new GridLayout(6,5); for(int cols = 0;cols 6;cols+) for(int rows = 0;rows 5;rows+ ) diamondsButtoncolsrows=new JButton(String.valueOf(gridcols+1rows+1); diamondsButtoncolsrows.addActionListener(this); centerPanel.add(diamondsButtoncolsrows); exitButton=new

5、JButton(退出); /退出按钮exitButton.addActionListener(this); resetButton=new JButton(重列); /重列按钮resetButton.addActionListener(this); newlyButton=new JButton(再来一局); /再来一局按钮newlyButton.addActionListener(this); southPanel.add(exitButton); southPanel.add(resetButton); southPanel.add(newlyButton); fractionLable.

6、setText(String.valueOf(Integer.parseInt(fractionLable.getText(); northPanel.add(fractionLable); mainFrame.setBounds(280,100,500,450); mainFrame.setVisible(true); public void randomBuild() /产生随机数 int randoms,cols,rows; for(int twins=1;twins=15;twins+) randoms=(int)(Math.random()*25+1); for(int alike=

7、1;alike=2;alike+) cols=(int)(Math.random()*6+1); rows=(int)(Math.random()*5+1); while(gridcolsrows!=0) cols=(int)(Math.random()*6+1); rows=(int)(Math.random()*5+1); this.gridcolsrows=randoms; public void fraction()/计数 fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText()+100)

8、; public void reload() int save = new int30; int n=0,cols,rows; int grid= new int87; for(int i=0;i=6;i+) for(int j=0;j=0) cols=(int)(Math.random()*6+1); rows=(int)(Math.random()*5+1); while(gridcolsrows!=0) cols=(int)(Math.random()*6+1); rows=(int)(Math.random()*5+1); this.gridcolsrows=saven; n-; ma

9、inFrame.setVisible(false); pressInformation=false; /这里一定要将按钮点击信息归为初始 init(); for(int i = 0;i 6;i+) for(int j = 0;j 5;j+ ) if(gridi+1j+1=0) diamondsButtonij.setVisible(false); public void estimateEven(int placeX,int placeY,JButton bz) /判断所单击的两次是否相同 if(pressInformation=false) x=placeX; y=placeY; secon

10、dMsg=gridxy; secondButton=bz; pressInformation=true; else x0=x; y0=y; fristMsg=secondMsg; firstButton=secondButton; x=placeX; y=placeY; secondMsg=gridxy; secondButton=bz; if(fristMsg=secondMsg & secondButton!=firstButton) xiao(); public void xiao() /相同的情况下能不能消去。if(x0=x &(y0=y+1|y0=y-1) | (x0=x+1|x0=x-1)&(y0=y) /判断是否相邻 remov

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 文学/艺术/历史 > 人文/社科

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号