g != null) {
walking.timer.stop();
}
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
buttons[i][j].setText("");//清除按钮的数字,设置名字为空
buttons[i][j].setForeground(null);
}
}
UI.jLabel_state.setText(" Move now?");
}
// 去掉全部砖
public static void blank() {
if (walking != null) {
walking.timer.stop();
}
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
buttons[i][j].setText("");
buttons[i][j].setForeground(null);
buttons[i][j].setSelected(true);
}
}
UI.jLabel_state.setText(" Move now?");
}
// 重画按钮图,根据rows、cols
public static JPanel drawButtons() {
buttons = new JToggleButton[rows][cols];
UI.jPanel_map = new JPanel(new GridLayout(rows, cols));
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
buttons[i][j] = new JToggleButton();
UI.jPanel_map.add(buttons[i][j]);
}
}
Main.ui.add(UI.jPanel_map, BorderLayout.CENTER);
Main.ui.setVisible(true);
return UI.jPanel_map;
}
// 根据brick[][]设置按钮障碍
public static void setBricks() {
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
buttons[i][j].setSelected(brick[i][j]);
}
}
}
// 根据现在按钮情况设置brick[][]数组,用于move()内前面
public static void readBricks() {
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
brick[i][j] = buttons[i][j].isSelected();
}
}
}
// 开始走
public static void move() {
if (walking != null) {
walking.timer.stop();
}
clean();
readBricks();
//readToFile();
walking = new Walking(brick);
}
/**
// 用于把绘制好地图数据写入文件
public static void readToFile() {
String out = "";
for (int i = 0; i < rows; i++) {
out += "{";
for (int j = 0; j < cols; j++) {
if (brick[i][j]) {
out += "true,";
}
else {
out += "false,";
}
}
out += "},\r\n";
}
hartech.JFile.stringToFile(out, "E:/dest.txt");
}
*/
// 复制二维数组
public static boolean[][] copyBoolean(boolean[][] in) {
int row = in.length, col = in[0].length;
boolean[][] out = new boolean[row][col];
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
out[i][j] = in[i][j];
}
}
return out;
}
}
2) UI模块--实现整个控制面板内组件的布局管理;
3)Walking模块--实现走迷宫的算法;
4)Applete模块--设置控制面板。
第二章 详细设计
package hartech.kids.maze;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
/**
*
Title: maze's MainUI
*
*
Description:
*
*
Date: 2006-08-31
*/
public class UI extends JPanel {
private static final long serialVersionUID = 59240
上一篇:
学生综合测评系统(C语言设计)
下一篇:
高陈基于Java超市账单管理系统