towerpoint.java

来自「JAVA写的图形化汉诺塔程序 swing实现」· Java 代码 · 共 46 行

JAVA
46
字号
package chapter1;
public class TowerPoint
{
	int x,y;          //the coordinate of the tower point 
	boolean aDisk;    //whether there is a disk at the tower point 
	Disk disk  = null;
	HannoiTower con = null;// the container of the disk
	public TowerPoint (int x,int y,boolean b)
	{
		this.x = x;
		this.y = y;
		aDisk = b;
	}
	public boolean isADisk()
	{
		return aDisk;
	}
	public void setIsDisk(boolean b)
	{
		aDisk = b;
	}
	public int getX()
	{
		return x;
	}
	public int getY()
	{
		return y;
	}
	public void setDisk(Disk disk,HannoiTower con)
	{
		this.con = con;
		con.setLayout(null);
		this.disk = disk;
		con.add(disk);
		int w = disk.getBounds().width;
		int h = disk.getBounds().height;
		disk.setBounds(x-w/2,y-h/2,w,h);
		this.aDisk = true;
		con.validate();
	}
	public Disk getDisk()
	{
		return disk;
	}
}

⌨️ 快捷键说明

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