📄 程序界面.java
字号:
/*
* Created on 2005-4-9
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
/**
* @author 陈凯
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class 程序界面 extends Applet implements ActionListener,ItemListener
{
//以下定义一组常量
public static final int 搜索法_广度优先=1;
public static final int 搜索法_深度优先=2;
public static final int 搜索法_有界深度优先=3;
public static final int 搜索法_最好优先=4;
public static final int 搜索法_局部择优=5;
public static final int 动画方式_显示搜索全过程=1;
public static final int 动画方式_显示解路径=2;
//以下是控件
private Label lbStartS=new Label("请选择开始状态:");
private CheckboxGroup cbgStartS=new CheckboxGroup();
private Checkbox cbxPreSet=new Checkbox("预设状态",false,cbgStartS);
private Checkbox cbxRand=new Checkbox("随机生成",false,cbgStartS);
private Canvas cvStartEnd=new Canvas();
private Label lbSelectMethod=new Label("请选择搜索方式:");
private Choice ccSelectMethod=new Choice();
private Label lbSetMaxNodeNum=new Label("请设置最大考擦结点数:");
private TextField txtSetMaxNodeNum=new TextField(11);
private Button btnSetMaxNodeNum=new Button(" 确定 ");
private Label lbSetSearchDepth=new Label("若为有界深度搜索请设置有界深度:");
private TextField txtSetSearchDepth=new TextField();
private Button btnSetSearchDepth=new Button(" 确定 ");
private Label lbAnMethod=new Label("请选择动画方式:");
private CheckboxGroup cbgAnMethod=new CheckboxGroup();
private Checkbox cbxShowAll=new Checkbox("显示搜索全过程",true,cbgAnMethod);
private Checkbox cbxShowPath=new Checkbox("显示解路径",false,cbgAnMethod);
private Label lbSetTime=new Label("设置每帧延迟时间:");
private TextField txtSetTime=new TextField(15);
private Button btnSetTime=new Button(" 确定 ");
private Canvas cvCurNode=new Canvas();
private Button btnAutoSearch=new Button("自动搜索");
private Button btnPre=new Button("上一步");
private Button btnNext=new Button("下一步");
private Button btnInit=new Button("初始化");
private TextArea txtaSay=new TextArea(8,45);
private Button btnShowSearchInfo=new Button(" 解信息 ");
private Button btnIntroduce=new Button(" 简 介 ");
private Button btnAboutme=new Button(" 关于我 ");
private Button btnClear=new Button(" 清 空 ");
private 九宫图 九宫图=new 九宫图();
private int 搜索方法=0;
private int 动画方式=1;
private long 每帧延时=1;
private int 解路径指针=0;
private int 解全过程指针=0;
private int 最大考察结点数=50000;
//初始化界面和数据
public void init()
{
this.cbxPreSet.addItemListener(this);
this.cbxRand.addItemListener(this);
this.ccSelectMethod.addItemListener(this);
this.txtSetMaxNodeNum.setText(""+this.最大考察结点数);
this.btnSetMaxNodeNum.addActionListener(this);
this.txtSetSearchDepth.setText("20");
this.九宫图.有界深度=Integer.parseInt(this.txtSetSearchDepth.getText());
this.btnSetSearchDepth.addActionListener(this);
this.cbxShowAll.addItemListener(this);
this.cbxShowPath.addItemListener(this);
this.txtSetTime.setText("1");
this.btnSetTime.addActionListener(this);
this.btnAutoSearch.addActionListener(this);
this.btnPre.addActionListener(this);
this.btnNext.addActionListener(this);
this.btnInit.addActionListener(this);
this.btnShowSearchInfo.addActionListener(this);
this.btnIntroduce.addActionListener(this);
this.btnAboutme.addActionListener(this);
this.btnClear.addActionListener(this);
this.setSize(380,585);
this.setBackground(new Color(220,230,255));
this.add(lbStartS);
this.add(this.cbxPreSet);
this.add(this.cbxRand);
this.cvStartEnd.setSize(350,100);
this.cvStartEnd.setBackground(new Color(250,250,255));
this.add(this.cvStartEnd);
this.add(this.lbSelectMethod);
this.ccSelectMethod.add("请选择一种搜索法");
this.ccSelectMethod.add("广度优先搜索法");
this.ccSelectMethod.add("深度优先搜索法");
this.ccSelectMethod.add("有界深度优先搜索法");
this.ccSelectMethod.add("最好优先搜索法");
this.ccSelectMethod.add("局部择优搜索法");
this.add(this.ccSelectMethod);
this.add(this.lbSetMaxNodeNum);
this.add(this.txtSetMaxNodeNum);
this.add(this.btnSetMaxNodeNum);
this.add(this.lbSetSearchDepth);
this.add(this.txtSetSearchDepth);
this.add(this.btnSetSearchDepth);
this.lbSetSearchDepth.disable();
this.txtSetSearchDepth.disable();
this.btnSetSearchDepth.disable();
this.add(this.lbAnMethod);
this.add(this.cbxShowAll);
this.add(this.cbxShowPath);
this.add(this.lbSetTime);
this.add(this.txtSetTime);
this.add(this.btnSetTime);
this.cvCurNode.setSize(350,100);
this.cvCurNode.setBackground(new Color(250,250,255));
this.add(this.cvCurNode);
this.add(this.btnAutoSearch);
this.add(this.btnPre);
this.add(this.btnNext);
this.add(this.btnInit);
this.add(this.txtaSay);
this.add(this.btnShowSearchInfo);
this.add(this.btnIntroduce);
this.add(this.btnAboutme);
this.add(this.btnClear);
this._初始化();
}
//初始化数据的方法
private void _初始化()
{
this.九宫图.初始化();
this.九宫图.OPEN表.加入结点(this.九宫图.开始结点);
this.解全过程指针=0;
this.解路径指针=0;
this.动画方式=程序界面.动画方式_显示搜索全过程;
this.btnAutoSearch.enable();
this.btnInit.enable();
this.btnNext.enable();
this.btnPre.disable();
this.cbxShowAll.setState(true);
this.cbxShowPath.setState(false);
this.txtaSay.appendText("系统被初始化!\n\n");
}
//延时的方法
private void _延时()
{
long t=this.每帧延时;
while(--t!=0);
}
//绘制开始状态和目标状态
private void _绘制开始目标结点(Graphics g)
{
g.setColor(new Color(10,10,0));
g.clearRect(40,10,80,80);
this.九宫图.开始结点.绘制九宫图结点(g,40,10,80);
g.drawLine(40+80+30,10+40,40+80+10+70,10+40);
g.drawLine(40+80+10+70-20,10+40-20,40+80+10+70,10+40);
g.drawLine(40+80+10+70-20,10+40+20,40+80+10+70,10+40);
this.九宫图.目标结点.绘制九宫图结点(g,40+80+10+70+30,10,80);
}
//绘制当前结点
private void _绘制当前结点(Graphics g)
{
g.setColor(new Color(10,10,0));
g.clearRect(130,10,80,80);
this.九宫图.取当前结点().绘制九宫图结点(g,130,10,80);
}
//绘制解路径状态
private void _绘制解路径(Graphics g)
{
九宫图结点 node=(九宫图结点)this.九宫图.解路径.elementAt(this.解路径指针);
g.setColor(new Color(10,10,0));
g.clearRect(130,10,80,80);
node.绘制九宫图结点(g,130,10,80);
}
//绘制搜索全过程状态
private void _绘制搜索全过程(Graphics g)
{
九宫图结点 node=(九宫图结点)this.九宫图.CLOSE表.elementAt(this.解全过程指针);
g.setColor(new Color(10,10,0));
g.clearRect(130,10,80,80);
node.绘制九宫图结点(g,130,10,80);
}
private boolean _单步搜索()
{
boolean retv;
switch(this.搜索方法)
{
case 程序界面.搜索法_广度优先:
{
retv=this.九宫图.单步广度优先搜索();
break;
}
case 程序界面.搜索法_深度优先:
{
retv=this.九宫图.单步深度优先搜索();
break;
}
case 程序界面.搜索法_有界深度优先:
{
retv=this.九宫图.单步有界深度优先搜索();
break;
}
case 程序界面.搜索法_最好优先:
{
retv=this.九宫图.单步最好优先搜索();
break;
}
case 程序界面.搜索法_局部择优:
{
retv=this.九宫图.单步局部择优搜索();
break;
}
default:
{
retv=true;
break;
}
}
return retv;
}
//事件处理方法
public void actionPerformed(ActionEvent e)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -