⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mazemouse.java~14~

📁 本软件是使用java 开发的
💻 JAVA~14~
📖 第 1 页 / 共 2 页
字号:
package datastructure;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Stack;

public class MazeMouse
    extends Panel
    implements Runnable, ActionListener {

  private Image offscreenImage;
  private Graphics offscreenGraphics;
  private int aWidth;
  private int aHeight;
  private Thread runner;
  private boolean runFlag;  //控制线程的运行
  public static JButton newButton;
  public static JButton stayButton;

  public static JButton runButton;
  public static JButton stepButton;
  CodeAnimationPanel codePanel;   //代码面板
  Panel centerpanel;
  JPanel eastpanel;
  JPanel  prampanel;
  JSplitPane splitpane;
  JTextField textfield00;
  JTextField textfield01;
  JTextField textfield11;
  JTextField textfield12;
  JTextField textfield21;
  JTextField textfield22;
  JTextField textfield31;
  JTextField textfield32;
  JTextField textfield41;
  JTextField textfield42;
  JButton [][] button;  //
  DealWith dealwith;   //
  boolean colorflag[][];  //障碍数组
  boolean  pathflag[][];  //走过的路,设置为true
  Color bgcolor;
  Image mouse[];
  int codePart=2;
  PosType start;  //开始位置
  PosType end;  //结束位置
  PosType curpos;   //当前位置
  int curstep=1;   //
  Stack mazeStack;  //java.util.stack 栈用来本程序的栈实现
  SElemType e;      //
  boolean doneFlag=false;
  boolean searchpath=false;
  private GlobalControls controlsPanel = new GlobalControls();
  int controls=0;
  SElemType bankup;
  boolean lockflag=false;
  ImageIcon mouseimg[]=new ImageIcon[5];


  public MazeMouse() {

    setLayout(new BorderLayout());
  }

  public void init() {
    e=new SElemType();
    String as[] = {
        "MazePath(MazeType maze,Pos start,Pos end)",
        "{ initStack(s); curpos=start;",
        " curstep=1;",
        " do{ ",
        "    if(Pass(curpos)) {",
        "       FootPrint(curpos);",
        "       e=(curstep,curpos,1);",
        "       Push(s,e); ",
        "       if(curpos==end) return(true);",
        "       curpos=Next(curpos,1); ",
        "       curstep++;  }",
        "    else {",
        "         if(!StackEmpty(s)){",
        "         pop(s,e)",
        "    while(e.di==4&&!StackEmpty(s)){",
        "     MarkPrint(e.seat); pop(s,e);  }",
        "    if(e.di<4){",
        "      e.di++; push(s,e);",
        "      curpos=NextPos(e.seat,e.di); }",
        " while(!StackEmpty(s));}",
        " return (false);",
        "}"};
  //  ImageIcon sendButtonnormalIcon = new ImageIcon(getClass().getResource(
   //  toolbarImagePath + "sendmesagenormal.png"));
    for(int imgcount=1;imgcount<=4;imgcount++)
    {
      mouseimg[imgcount]=new ImageIcon(getClass().getResource("/images/mouse"+imgcount+".gif"));
    }
    dealwith=new DealWith();
    bgcolor=this.getBackground();
    textfield00 = new JTextField("变量名");
    textfield00.setEditable(false);
    textfield01 = new JTextField("变量值");
    textfield01.setEditable(false);
    textfield11 = new JTextField("");
    textfield11.setEditable(false);
    textfield12 = new JTextField(" ");
    textfield12.setEditable(false);
    textfield21 = new JTextField("");
    textfield21.setEditable(false);
    textfield22 = new JTextField("");

    textfield22.setEditable(false);
    textfield31 = new JTextField("");
    textfield31.setEditable(false);
    textfield32 = new JTextField();
    textfield32.setEditable(false);
    textfield41 = new JTextField("");
    textfield41.setEditable(false);
    textfield42 = new JTextField();
    textfield42.setEditable(false);
    prampanel = new JPanel();
    prampanel.setLayout(new GridLayout(5,2));
    prampanel.add(textfield00);
    prampanel.add(textfield01);
    prampanel.add(textfield11);
    prampanel.add(textfield12);
    prampanel.add(textfield21);
    prampanel.add(textfield22);
    prampanel.add(textfield31);
    prampanel.add(textfield32);
    prampanel.add(textfield41);
    prampanel.add(textfield42);

    eastpanel = new JPanel();
    eastpanel.setLayout(new BorderLayout());
    codePanel = new CodeAnimationPanel(as);
  //  codePanel.add
    eastpanel.add(codePanel,BorderLayout.NORTH);
    eastpanel.add( prampanel,BorderLayout.SOUTH);
   //this.add(eastpanel,L)
    centerpanel=new Panel();
    this.add(eastpanel,BorderLayout.EAST);
    this.add(centerpanel,BorderLayout.CENTER);
    centerpanel.setLayout(null);
    button=new JButton[8][8];
    colorflag=new boolean[10][10];
    pathflag=new boolean[8][8];
      for(int i=0;i<8;i++)
       for(int j=0;j<8;j++)
      {
        button[i][j] = new JButton("");
        button[i][j].addActionListener(dealwith);
        centerpanel.add(button[i][j]);
        button[i][j].setName(String.valueOf(i*8+j));
        button[i][j].setBounds(60+j*40,80+i*40,40,40);
        pathflag[i][j]=false;
        colorflag[i+1][j+1]=false;
      }

    for(int i=0;i<10;i++)  //初始化迷宫的外围不可以走
      for(int j=0;j<10;j++)
      {
        if(i==0||i==9||j==0||j==9)
        {
          colorflag[i][j]=true;
        }
      }

    for(int imgcount=0;imgcount<4;imgcount++)
   {
     // mouse[imgcount]=Root.mousegif[imgcount];
   }

  splitpane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,centerpanel,eastpanel);
    splitpane.setAutoscrolls(true);
    splitpane.setDividerSize(10);
   // splitpane.set
   splitpane.setOneTouchExpandable(true);
   splitpane.setDividerLocation(450);
   splitpane.revalidate();

    this.add(splitpane);
     newButton = new JButton("新建");

     newButton.addActionListener(this);

    runButton = new JButton("执行");

    runButton.addActionListener(this);

    stepButton = new JButton("单步");

    stepButton.addActionListener(this);
    stayButton = new JButton("暂停");

    stayButton.addActionListener(this);

    runFlag = false;

    paintComponents(getGraphics());

    show();
  }

  public void paint(Graphics g)

  {


  }

  public void update(Graphics g) {
    paint(g);
  }

  public void actionPerformed(ActionEvent actionevent) {
    if (actionevent.getSource() == newButton) {
      this.stop();
      for(int i=0;i<8;i++)
      for(int j=0;j<8;j++)
     {
       button[i][j].setBackground(bgcolor);
       pathflag[i][j]=false;
       colorflag[i+1][j+1]=false;
       button[i][j].setIcon(null);
     }
      codePart=2;
      codePanel.highlight(1);
      runFlag = true;
      doneFlag=false;
      lockflag=false;
      stepButton.setEnabled(true);
      stayButton.setEnabled(true);
      runButton.setEnabled(true);



    }
    else

    if (actionevent.getSource() == runButton) {
      lockflag=true;
      try {
            this.start();
          }
          catch (Exception exp) {
            exp.toString();
          }
          runFlag = true;

    }
    else

    if (actionevent.getSource() == stepButton) {
      runFlag = false;
      MazePath();
    }
    else if (actionevent.getSource() == stayButton) {
      runFlag = false;
    }

    repaint();
  }

  public void start() {
    if (runner == null) {
      runner = new Thread(this);
      runner.start();
    }
  }

  public void stop() {
    runner = null;
  }

  public void run() {
      while (Thread.currentThread() == this.runner) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -