连连看的连线怎么写java_求助 这个连连看的方法地方该怎么写

本文介绍了一个基于Java Swing的连连看游戏界面设计实现方法。通过创建各类按钮与标签,设置了游戏的基本布局,并实现了开始游戏后的界面元素动态更新。文章详细展示了如何使用事件监听器响应用户的操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

package UI;

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.IOException;

import javax.sound.midi.InvalidMidiDataException;

import javax.sound.midi.MidiUnavailableException;

import javax.swing.*;

import javax.swing.table.DefaultTableModel;

//这个是主界面的

public class Jiemian extends JFrame {

JButton 设置按钮;

JButton 帮助按钮;

JButton 关于按钮;

JButton 开始按钮;

JButton 刷新按钮;

JButton 提示按钮;

JButton 炸弹按钮;

JButton 演示按钮;

JLabel 界面标签;

public Jiemian(){

//设置窗体***********************************************

this.setTitle("连连看");

this.setSize(830,500);

this.setLocationRelativeTo(null);

this.setLayout(null);

this.setResizable(false);

this.getContentPane().setBackground(Color.lightGray);//

wj();

this.setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//监听****************************************************

设置按钮.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

try {

new Shezhi();

} catch (InvalidMidiDataException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

} catch (IOException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

} catch (MidiUnavailableException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

}

});

帮助按钮.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

new Bangzhu();

}

});

关于按钮.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

new Guanyu();

}

});

开始按钮.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

dispose();

new Startgame();

}

});

//****************************************************

}

public void wj()

{

设置按钮=new JButton();

this.getContentPane().add(设置按钮);

设置按钮.setBounds(0, 10, 87,30);

帮助按钮=new JButton();

this.getContentPane().add(帮助按钮);

帮助按钮.setBounds(90, 10, 87,30);

关于按钮=new JButton();

this.getContentPane().add(关于按钮);

关于按钮.setBounds(180, 10, 87,30);

开始按钮=new JButton();

this.getContentPane().add(开始按钮);

开始按钮.setBounds(665, 50, 156,48);

刷新按钮=new JButton();

this.getContentPane().add(刷新按钮);

刷新按钮.setBounds(665, 130, 156,48);

提示按钮=new JButton();

this.getContentPane().add(提示按钮);

提示按钮.setBounds(665, 220, 156,48);

炸弹按钮=new JButton();

this.getContentPane().add(炸弹按钮);

炸弹按钮.setBounds(665, 310, 156,48);

演示按钮=new JButton();

this.getContentPane().add(演示按钮);

演示按钮.setBounds(665, 400, 156,48);

界面标签=new JLabel();

this.getContentPane().add(界面标签);

界面标签.setBounds(0, 45, 655,423);

界面标签.setBorder(BorderFactory.createLineBorder(Color.blue));

Icon imgshezhi = new ImageIcon(ClassLoader.getSystemResource("images/setup.gif"));

设置按钮.setIcon(imgshezhi);

Icon imgbangzhu = new ImageIcon(ClassLoader.getSystemResource("images/help.gif"));

帮助按钮.setIcon(imgbangzhu);

Icon imgguanyu = new ImageIcon(ClassLoader.getSystemResource("images/about.gif"));

关于按钮.setIcon(imgguanyu);

Icon kaishi = new ImageIcon(ClassLoader.getSystemResource("images/start.gif"));

开始按钮.setIcon(kaishi);

Icon shuaxin = new ImageIcon(ClassLoader.getSystemResource("images/refresh.gif"));

刷新按钮.setIcon(shuaxin);

Icon tishi = new ImageIcon(ClassLoader.getSystemResource("images/hint.gif"));

提示按钮.setIcon(tishi);

Icon zhadan = new ImageIcon(ClassLoader.getSystemResource("images/bomb.gif"));

炸弹按钮.setIcon(zhadan);

Icon yanshi = new ImageIcon(ClassLoader.getSystemResource("images/demo.gif"));

演示按钮.setIcon(yanshi);

}

public static void main(String args []){

new Jiemian();

}

}

//这个是点开始游戏按钮后的

package UI;

import java.awt.Color;

import java.awt.Window;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.BorderFactory;

import javax.swing.Icon;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

public class Startgame extends JFrame {

JButton a;

int index;

JButton wj[][] = new JButton[9][11];//游戏按钮数组

int w [][] = new int [9][11];

public Startgame()

{

Jiemian jm = new Jiemian();

jm.界面标签=new JLabel();

jm.getContentPane().add(jm.界面标签);

jm.界面标签.setBounds(1, 47, 650,418);

jm.界面标签.setBorder(BorderFactory.createLineBorder(Color.yellow));

for(int i=0;i<9;i++)

{

for(int j=0;j<11;j++)

{

wj[i][j]=new JButton();

jm.getContentPane().add(wj[i][j]);

wj[i][j].setBounds(j*50+60,i*45+50,31,34);

}

}

//声明图片**********************************************

for(int i=0;i<9;i++)

{

for(int j=0;j<11;j++)

{

final int randoms=(int)(Math.random()*25+1); //产生随机数

Icon imga = new ImageIcon(ClassLoader.getSystemResource("images/"+(randoms)+".gif"));

wj[i][j].setIcon(imga);

wj[i][j].setName(randoms+"");

//***************************************************

wj[i][j].addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

JButton jb = (JButton)e.getSource();

String n = jb.getName();

System.out.println(n);

bijiao(Integer.parseInt(n));

}

});

}

}

}

public void bijiao(int f)

{

for(int i=0;i<9;i++)

{

for(int j=0;j<11;j++)

{

if(wj[i][j].getName().equals(f+""))

{

wj[i][j].setVisible(false);

}

}

}

}

public static void main(String [] args)

{

new Startgame();

}

}

求助 这个Startgame 我该怎么写这个游戏的方法

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值