c class lianliankan implements ActionListener
6. {
7. JFrame mainFrame; //主面板
8. Container thisContainer;
9. JPanel centerPanel,southPanel,northPanel; //子面板
10. JButton diamondsButton[][] = new JButton[6][5];//游戏按钮数组
11. JButton exitButton,resetButton,newlyButton; //退出,重列,重新开始按钮
12. JLabel fractionLable=new JLabel("0"); //分数标签
13. JButton firstButton,secondButton; //分别记录两次被选中的按钮
14. int grid[][] = new int[8][7];//储存游戏按钮位置
15. static boolean pressInformation=false; //判断是否有按钮被选中
16. int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戏按钮的位置坐标
17. int i,j,k,n;//消除方法控制
18. public void init(){
19. } //开始方法:
20. }
21. public void randomBuild() {
22. } //产生随基数
23. public void fraction(){
24. }//计数
25. public void reload() {
26. } //窗体的重新加载
27. public void estimateEven(int placeX,int placeY,JButton bz) {
28. } //判断两次点击的两次数:
29. public void xiao() { //相同的情况下能不能消去。仔细分析,不一条条
30. } //相同的情况下能不能消去。仔细分析,不一条条
31.
32. public void linePassOne(){
33. } //判断行是否可以消除:
34. public void rowPassOne(){
35. } //判断列是否可消除;
36. public void remove(){
37. } //消除所选按钮;
38. public void actionPerformed(ActionEvent e) {
39. } //监听事件;
40. public static void main(String[] args) {
41. }//游戏入口;
二.详细代码编写:
//连连看java
源代码 import 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 JButton[6][5];//游戏按钮数组
JButton exitButton,resetButton,newlyButton; //退出,重列,重新开始按钮
JLabel fractionLable=new JLabel("0"); //分数标签
JButton firstButton,secondButton; //分别记录两次被选中的按钮
int grid[][] = new int[8][7];//储存游戏按钮位置
static boolean pressInformation=false; //判断是否有按钮被选中
int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戏按钮的位置坐标
int i,j,k,n;//消除方法控制
1.开始方法:
public void init(){
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.add(northPanel,"North");
centerPanel.setLayout(new GridLayout(6,5));
for(int cols = 0;cols < 6;cols++){
for(int rows = 0;rows < 5;rows++ ){
diamondsButton[cols][rows]=new JButton(String.valueOf(grid[cols+1][rows+1]));
diamondsButton[cols][rows].addActionListener(this);
centerPanel.add(diamondsButton[cols][rows]);
}
}
exitButton=new JButton("退出");
exitButton.addActionListener(this);
resetButton=new JButton("重列");
resetButton.addActionListener(this);
newlyButton=new JButton("再来一局");
new