资源简介
用java做的九宫格游戏,适合初学者进行学习
代码片段和文件信息
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.util.*;
/**
* A PuzzleTile class; this class inherits from JPanel.
*
* The tiles do not have any numbers painted on them yet.
* The only indication you will be able to visibly see at this point
* is that the 0 tile should be white and the rest gray.
*
* @author Laurissa
* @version 1.0
* @author Paula
* @version 1.1
* @author Huan Gao
* @version 1.2
*/
public class PuzzleTile extends JPanel {
private String tileNumber;
//set a instance variable so that I can get the value on the PuzzleTile
public int pastNum;
/**
* This constructor takes in the number you would like
* displayed on this panel and saves it as the String
* instance variable tileNumber.
* Note that you will still have to paint it onto the panel.
* You should do that by overriding the method:
* public void paintComponent(Graphics g){}.
*
* @param number The number to paint on the panel.
*/
public PuzzleTile(int number) {
super();
pastNum= number;
if (number == 0) {
this.setBackground(Color.white);
}
else {
this.setBackground(Color.darkGray);
}
this.tileNumber = ““ + number;
}
//set a method that can set the number displayed on the PuzzleTile
public void setString(String str)
{
tileNumber=str;
}
public String getString()
{
return tileNumber;
}
public void paintComponent(Graphics g) {
Font fnt=new Font(“Arial“Font.BOLD30);
g.setFont(fnt);
g.setColor(Color.white);
super.paintComponent(g);
FontMetrics fm=g.getFontMetrics(fnt);
int num1=fm.stringWidth(tileNumber);
int num2=fm.getAscent();
int getspace= fm.getMaxAscent();
int num3=getWidth()/2-num1/2;
int num4=getHeight()/2-num2/2+getspace;
g.drawString(tileNumbernum3num4);
}
// You will need to provide more methods to interact with your
// main program.
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
-rw------- 590 2012-05-18 23:49 MiniProjectCode\JavaDoc\allclasses-fr
-rw------- 570 2012-05-18 23:49 MiniProjectCode\JavaDoc\allclasses-nofr
-rw------- 3280 2012-05-18 23:49 MiniProjectCode\JavaDoc\constant-values.html
-rw------- 3264 2012-05-18 23:49 MiniProjectCode\JavaDoc\deprecated-list.html
-rw------- 6510 2012-05-18 23:49 MiniProjectCode\JavaDoc\help-doc.html
-rw------- 6885 2012-05-18 23:49 MiniProjectCode\JavaDoc\index-all.html
-rw------- 1229 2012-05-18 23:49 MiniProjectCode\JavaDoc\index.html
-rw------- 3718 2012-05-18 23:49 MiniProjectCode\JavaDoc\overview-tree.html
-rw------- 706 2012-05-18 23:49 MiniProjectCode\JavaDoc\package-fr
-rw------- 2 2012-05-18 23:49 MiniProjectCode\JavaDoc\package-list
-rw------- 3709 2012-05-18 23:49 MiniProjectCode\JavaDoc\package-summary.html
-rw------- 3727 2012-05-18 23:49 MiniProjectCode\JavaDoc\package-tree.html
-rw------- 2313 2012-05-18 23:49 MiniProjectCode\JavaDoc\resources\background.gif
-rw------- 291 2012-05-18 23:49 MiniProjectCode\JavaDoc\resources\tab.gif
-rw------- 10701 2012-05-18 23:49 MiniProjectCode\JavaDoc\resources\ti
-rw------- 849 2012-05-18 23:49 MiniProjectCode\JavaDoc\resources\ti
-rw------- 13280 2012-05-18 23:49 MiniProjectCode\JavaDoc\SlidingPuzzle.html
-rw------- 11613 2012-05-18 23:49 MiniProjectCode\JavaDoc\st
-rw------- 1503 2012-05-18 17:02 MiniProjectCode\PuzzleTile.class
-rw------- 2350 2012-05-18 13:11 MiniProjectCode\PuzzleTile.java
-rw------- 5292 2012-05-19 00:49 MiniProjectCode\SlidingPuzzle.class
-rw------- 5311 2012-05-18 23:58 MiniProjectCode\SlidingPuzzle.java
drwx------ 0 2013-01-24 21:05 MiniProjectCode\JavaDoc\resources
drwx------ 0 2013-01-24 21:05 MiniProjectCode\JavaDoc
drwx------ 0 2013-01-24 21:05 MiniProjectCode
----------- --------- ---------- ----- ----
87693 25
- 上一篇:小型BBS论坛 jsp mysql数据库
- 下一篇:简单的JSP界面
相关资源
- java 显示一个图像的轮廓
- MQTT消息队列mosquitto的java方式实现客户
- Java记事本源码和课程设计报告
- java-client-5.0.0-SNAPSHOT.jar
- 将JTable中的数据保存到Excel中
- 读取Excel数据到JTable
- Java多线程自动播放图片的小程序
- JAVA播放器的源代码 5个写法
-
Java 数据结构 ap
plet演示 - cmpp2.0 java实现
- sqoop2 java API从oracle导数据到HDFS开发总
- javassist包
- java葵花宝典&九阴真经
- 修改servlet和jsp模板.zip
- javax.persistence-2.0.0.jar
- protobuf-java-2.6.0.jar
- Java RMI 聊天室 源码
- java控制台购物系统java购物系统
- JAVA自动获取文件的编码工具类
- java-贪心算法-物流派件用车最少
- java金融项目开发-信贷管理业务
- java基于socket/server的多线程聊天室程序
- Java FTP 实现跨服务器文件上传
- Java课程设计-五子棋226111
- java面向对象 纸牌 含详细注释
- 非常简单实用的jsp实现树型菜单,不
- JAVA 控制台 简单的图书管理系统
- SM4java实现
- socket的应用 计算机网络 java版
- jsp+javabean+servlet库存管理系统
评论
共有 条评论