Java课程设计

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Java课程设计题目:人物连连看

一、设计题目

人物连连看

二、设计目的

Java语言是当今流行的网络编程语言,它具有面向对象、跨平台、分布应用等特点。面向对象的开发方法是当今世界最流行的开发方法,它不仅具有更贴近自然的语义,而且有利于软件的维护和继承。学会Java程序的开发的环境搭建和配置,并在实际中学习和掌握Java程序开发的全过程。进一步熟悉Java程序设计语言的基础内容,如用户图形界面设计、Java多线程编程、Applet程序的设计。

三、功能描述

通过Java语言编写一个人物连连看程序。程序实现以下几个功能:

1、判断鼠标点击的两张图片是否相同;

2、判断2张图片是否可以相连;

3、判断时间;

4、判断是否使用炸弹,炸弹剩余数目,自动生成路径消除两张相同图片;

5、判断剩余图片,是否胜利。

四.流程图

五、源代码

1.

import .URL;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import cn.elva.Settings;

import cn.elva.model.ArrayPoint;

public class ChessButton extends JButton

{

// 按钮所对应的数组中的值和位置,用ArrayPoint结构来表示

protected ArrayPoint point = null;

public ChessButton(int row, int col, int value)

{

this(new ArrayPoint(row, col, value));

}

public ChessButton(ArrayPoint point)

{

this.point = point;

String name ="Resource/"+point.getValue() + Settings.RELEX;

URL url = ChessButton.class.getResource(name);

ImageIcon icon = new ImageIcon( url );

this.setIcon(icon);

}

public ChessButton()

{

this(new ArrayPoint(0, 0, 0));

}

public ArrayPoint getPoint()

{

return point;

}

public void setPoint(ArrayPoint point)

{

this.point = point;

}}

2.

import java.awt.BorderLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JFrame;

import javax.swing.JMenu;

import javax.swing.JMenuBar;

import javax.swing.JMenuItem;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.SwingUtilities;

import javax.swing.Timer;

import cn.elva.Settings;

import cn.elva.model.Map;

public class MainFrame extends JFrame

{

private static final long serialVersionUID = 1L;

private int bombCount = Settings.BOMBCOUNT; //炸弹的次数private JPanel jContentPane = null;

private JMenuBar menuBar = null;

private JMenu fileMenu = null;

private JMenuItem reloadItem = null;

private JMenuItem startItem = null;

private JMenuItem bombItem = null; //炸弹

private JMenuItem exitItem = null;

private MapUI mapUI = null;

// 游戏开始时间

private long startTime;

// 结束时间

private long endTime;

private Timer timer = null;

// private JMenuItem ti

private JMenuBar initMenuBar()

{

if (menuBar == null)

{

menuBar = new JMenuBar();

fileMenu = new JMenu("文件");

startItem = new JMenuItem("开始游戏");

startItem.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

reload();

}

});

reloadItem = new JMenuItem("重来一次");

reloadItem.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

相关文档
最新文档