📄 towerpoint.java
字号:
/* * TowerPoint.java * * Created on 2007年10月4日, 下午6:07 * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */package 汉诺塔;/** * * @author baili */import java.awt.*;import java.awt.event.*;import java.util.*;public class TowerPoint { int x,y; int startX,startY; boolean 有盘子; Disk 盘子=null; HannoiTower con=null; TowerPoint start; //Thread t; //Timer timer; public TowerPoint(int x,int y,boolean boo) { this.x=x; this.y=y; 有盘子=boo; // t=new Thread(this); } public boolean 是否有盘子() { return 有盘子; } public void set有盘子(boolean boo) { 有盘子=boo; } public int getX() { return x; } public int getY() { return y; } public void 放置盘子1(Disk 盘子,HannoiTower con) { this.盘子=盘子; this.con=con; con.setLayout(null); con.add(盘子); int w=盘子.getBounds().width; int h=盘子.getBounds().height; 盘子.setBounds(x-w/2,y-h/2,w,h); con.validate(); 有盘子=true; } public void 放置盘子(Disk 盘子,HannoiTower con,TowerPoint start1) { // timer=new Timer(this,1000); start=start1; startX=start.getX(); startY=start.getY(); // this.start=start; this.con=con; this.盘子=盘子; con.setLayout(null); con.add(盘子); int w=盘子.getBounds().width; int h=盘子.getBounds().height; // con.validate(); // t.start(); int deltaX=1; float deltaY; int x1=startX,y1=startY; while(x1!=x) { try { Thread.currentThread().sleep(10); } catch(Exception ee) { } if(startX<x) { x1+=deltaX; deltaY=(y-startY)*(x1-startX)/(x-startX); y1=startY+(int)deltaY; } else { x1-=deltaX; deltaY=(y-startY)*(x1-startX)/(x-startX); y1=startY+(int)deltaY; } 盘子.repaint(); 盘子.setBounds(x1-w/2,y1-h/2,w,h); con.repaint(); } // 盘子.setBackground(Color.GREEN); 有盘子=true; } public Disk 获取盘子() { return 盘子; } /* public void run() { int deltaX=2; float deltaY; int x1=startX,y1=startY; while(x1<=x&&y1<=y); { con.setLayout(null); con.add(盘子); int w=盘子.getBounds().width; int h=盘子.getBounds().height; 盘子.setBounds(x1-w/2,y1-h/2,w,h); con.validate(); try { t.sleep(1000); } catch(Exception ee) { } x1+=deltaX; deltaY=(y-startY)*(x1-startX)/(x-startX); y1=startY+(int)deltaY; } 有盘子=true; }*/}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -