Java处理迷宫疑问

[文件] MyFinal.java ~ 4KB    下载(8) package com.mingrui.recursion;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class Test19_8 extends JFrame{
	private Cell[][] board=new Cell[8][8];
	private JButton jbFindPath=new JButton("找到未来·");
	private JButton jbClearPant=new JButton("铲除途径");
	private JPanel jpUp,jpBut;
	
	Test19_8(){
		setSize(345,256);
		setResizable(false);
		setDefaultCloseOperation(3);
		setLocationRelativeTo(null);
		jpUp=new JPanel();
		jpBut=new JPanel();
		jpUp.setLayout(new GridLayout(8,8,2,2));
		for(int i=0;i<8;i  ){
			for(int j=0;j<8;j  ){
				board[i][j]=new Cell();
				jpUp.add(board[i][j]);
			}
		}
		add(jpUp,BorderLayout.CENTER);
		jpBut.add(jbFindPath);
		jpBut.add(jbClearPant);
		add(jpBut,BorderLayout.SOUTH);
		jbFindPath.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				findPath();
			}			
		});
		jbClearPant.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				clearPath();
			}
		});
		setVisible(true);
	}
	public static void main(String [] args){
		new Test19_8();
	}
	public void findPath(){
		if(findPath(0,0)){
			System.out.println("我找到了");
		}
		else
			System.out.println("哎,白忙了,没找到");
	}
	public boolean findPath(int row,int col){
		board[row][col].visit();
		if(row==7
posted @ 2013-03-04 02:31  chinadiy197601  阅读(293)  评论(0编辑  收藏  举报