?? tower.java
字號:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Tower extends Frame implements ActionListener,Runnable
{
HannoiTower tower=null;
Button renew,auto=null;
char towerName[]={'A','B','C'};
int 盤子數(shù)目,盤寬,盤高;
Thread thread;
TextArea 信息條=null;
public Tower()
{
thread=new Thread(this);
盤子數(shù)目=5;
盤寬=80;
盤高=18;
信息條=new TextArea(12,12);
信息條.setText(null);
tower=new HannoiTower(盤子數(shù)目,盤寬,盤高,towerName,信息條);
renew=new Button("重新開始");
auto=new Button("自動(dòng)演示搬盤子");
renew.addActionListener(this);
auto.addActionListener(this);
add(tower,BorderLayout.CENTER);
add(renew,BorderLayout.SOUTH);
add(auto,BorderLayout.NORTH);
add(信息條,BorderLayout.EAST);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
});
setVisible(true);
setBounds(60,20,670,540);
validate();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==renew)
{
if(!(thread.isAlive()))
{
this.remove(tower);
信息條.setText(null);
tower=new HannoiTower(盤子數(shù)目,盤寬,盤高,towerName,信息條);
add(tower,BorderLayout.CENTER);
validate();
}
else
{
}
}
if(e.getSource()==auto)
{
if(!(thread.isAlive()))
{
thread=new Thread(this);
}
try
{
thread.start();
}
catch(Exception eee)
{
}
}
}
public void run()
{
this.remove(tower);
信息條.setText(null);
tower=new HannoiTower(盤子數(shù)目,盤寬,盤高,towerName,信息條);
add(tower,BorderLayout.CENTER);
validate();
tower.自動(dòng)演示搬運(yùn)盤子(盤子數(shù)目,towerName[0] ,towerName[1],towerName[2]);
}
public static void main(String args[])
{
new Tower();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -