• 大小: 46KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-06
  • 语言: Java
  • 标签: java连连  

资源简介

绚丽的UI界面,带有音乐,是新手练习的好材料,下载就能用。

资源截图

代码片段和文件信息

package LianLianKan;

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javax.swing.*;

public class LianLianKan extends Jframe {

private static int Jframe_WIDTH = 400 JFRMAE_HEIGHT = 500;
private int x = 30 y = 25;
private static int countofclicked = 0;// 用在内部那里
private Random rd = new Random();

private Icon[] fruiticons = new Icon[] {

new ImageIcon(getClass().getResource(“/lianliankanimages/banana.jpg“))
new ImageIcon(getClass().getResource(“/lianliankanimages/apple.jpg“))
new ImageIcon(getClass().getResource(“/lianliankanimages/mango.jpg“))
new ImageIcon(getClass().getResource(“/lianliankanimages/orange.jpg“))
new ImageIcon(getClass().getResource(“/lianliankanimages/peach.jpg“))
new ImageIcon(getClass().getResource(“/lianliankanimages/pineapple.jpg“))
new ImageIcon(getClass().getResource(“/lianliankanimages/strawberry.jpg“))
new ImageIcon(getClass().getResource(“/lianliankanimages/pear.jpg“))
};

private JToolBar menubar = new JToolBar();
private JMenu restart = new JMenu(“重新开始“) stoporcontinue = new JMenu(“暂停/继续“);
private JButton endgamebutton = new JButton(“结束“);
private JPanel 
toolpanel = new JPanel()
taskpanel = new JPanel();
private static JPanel fruitpanel = new JPanel();
private static List jlabels = new ArrayList();
private MyMouseListener mouselistener = new MyMouseListener();

public LianLianKan() {
super(“连连看游戏“);
toolpanel.setBackground(Color.blue);
taskpanel.setBackground(Color.green);
toolpanel.setLayout(new FlowLayout(FlowLayout.LEFT));
fruitpanel.setLayout(new GridLayout(8 8));

this.add(toolpanel BorderLayout.NORTH);
this.add(fruitpanel BorderLayout.CENTER);
this.add(taskpanel BorderLayout.SOUTH);
toolpanel.add(menubar);
menubar.add(restart);
menubar.add(stoporcontinue);
taskpanel.add(endgamebutton);
createlevel();

// pack();
this.setSize(Jframe_WIDTH JFRMAE_HEIGHT);
this.setVisible(true);
this.setResizable(false);
this.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
}
//生成水果布局,以后能扩展成为关卡
public void createlevel() {
int keykey2;
Icon turnjlabelicon1turnjlabelicon2;
// 生成64个JLabel并确保每个图片的个数都为偶数
for (int i = 0; i < 64; ) {
jlabels.add(new JLabel());
jlabels.add(new JLabel());
key = rd.nextInt(8);
jlabels.get(i).setIcon(fruiticons[key]);
jlabels.get(i+1).setIcon(fruiticons[key]);
jlabels.get(i).addMouseListener(mouselistener);
jlabels.get(i+1).addMouseListener(mouselistener);
fruitpanel.add(jlabels.get(i));
fruitpanel.add(jlabels.get(i+1));
i = i+2;
}
//进行图片的的打乱
for(int i=0;i key = rd.nextInt(64);
key2 = rd.nextInt(64);
turnjlabelicon1 = jlabels.get(key).getIcon();
turnjlabelicon2 = jlabels.get(ke

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-10-26 10:52  FunnyGame\
     文件         301  2016-10-18 20:27  FunnyGame\.classpath
     文件         385  2016-10-18 20:27  FunnyGame\.project
     目录           0  2016-10-26 10:52  FunnyGame\.settings\
     文件         598  2016-10-18 20:27  FunnyGame\.settings\org.eclipse.jdt.core.prefs
     目录           0  2016-10-26 10:52  FunnyGame\bin\
     目录           0  2016-10-26 10:52  FunnyGame\bin\LianLianKan\
     目录           0  2016-10-26 10:52  FunnyGame\bin\lianliankanimages\
     文件        1004  2016-10-20 10:38  FunnyGame\bin\lianliankanimages\apple.jpg
     文件        1076  2016-10-20 10:38  FunnyGame\bin\lianliankanimages\banana.jpg
     文件         663  2016-10-20 16:07  FunnyGame\bin\lianliankanimages\blank.jpg
     文件        1014  2016-10-20 10:38  FunnyGame\bin\lianliankanimages\mango.jpg
     文件        1970  2016-10-20 10:38  FunnyGame\bin\lianliankanimages\orange.jpg
     文件        1721  2016-10-20 10:38  FunnyGame\bin\lianliankanimages\peach.jpg
     文件        1441  2016-10-20 10:38  FunnyGame\bin\lianliankanimages\pear.jpg
     文件        2072  2016-10-20 10:38  FunnyGame\bin\lianliankanimages\pineapple.jpg
     文件        1819  2016-10-20 10:38  FunnyGame\bin\lianliankanimages\strawberry.jpg
     文件        5593  2016-10-26 10:50  FunnyGame\bin\LianLianKan\LianLianKan$MyMouseListener.class
     文件        4495  2016-10-26 10:50  FunnyGame\bin\LianLianKan\LianLianKan.class
     目录           0  2016-10-26 10:52  FunnyGame\bin\number\
     文件        2992  2016-10-24 20:44  FunnyGame\bin\number\CompareTwonumber.class
     文件        1736  2016-10-24 16:02  FunnyGame\bin\number\Yishengshangban.class
     文件       17710  2016-10-18 22:25  FunnyGame\hs_err_pid2436.log
     目录           0  2016-10-26 10:52  FunnyGame\src\
     目录           0  2016-10-26 10:52  FunnyGame\src\LianLianKan\
     目录           0  2016-10-26 10:52  FunnyGame\src\lianliankanimages\
     文件        1004  2016-10-20 10:38  FunnyGame\src\lianliankanimages\apple.jpg
     文件        1076  2016-10-20 10:38  FunnyGame\src\lianliankanimages\banana.jpg
     文件         663  2016-10-20 16:07  FunnyGame\src\lianliankanimages\blank.jpg
     文件        1014  2016-10-20 10:38  FunnyGame\src\lianliankanimages\mango.jpg
     文件        1970  2016-10-20 10:38  FunnyGame\src\lianliankanimages\orange.jpg
............此处省略8个文件信息

评论

共有 条评论