📄 ersbox.java
字号:
/**
* File: ErsBox.java
* User: Administrator
* Describe: 俄罗斯方块的 Java 实现
*/
import java.awt.*;
/**
* 方格类,是组成块的基本元素,用自己的颜色来表示块的外观
*/
public class ErsBox implements Cloneable
//(A class implements the Cloneable interface to indicate to the Object.clone() method that it is legal for that method to make a field-for-field copy of instances of that class)
{
private boolean isColor;
private Dimension size = new Dimension();
//(Creates an instance of Dimension with a width of zero and a height of zero)
/**
* 方格类的构造函数
* @param isColor 是不是用前景色来为此方格着色,
* true前景色,false用背景色
*/
public ErsBox(boolean isColor)
{
this.isColor = isColor;
}
/**
* 此方格是不是用前景色表现
* @return boolean,true用前景色表现,false用背景色表现
*/
public boolean isColorBox()//用于说明方格在画布上显示的方式,即用颜色说明
{return isColor;}
/**
* 设置方格的颜色,
* @param isColor boolean,true用前景色表现,false用背景色表现
*/
public void setColor(boolean isColor)
{this.isColor = isColor;}
/**
* 得到此方格的尺寸
* @return Dimension,方格的尺寸
*/
public Dimension getSize()
{
return size;//size是Dimension 的实例
}
/**
* 设置方格的尺寸
* @param size Dimension,方格的尺寸
*/
public void setSize(Dimension size)
{
this.size = size;
}
/**
* 覆盖Object的Object clone(),实现克隆
* @return Object,克隆的结果
*/
public Object clone() //Cloneable接口的抽象方法在此实现
{
Object cloned = null;
try
{
cloned = super.clone();
} catch (Exception ex) {
ex.printStackTrace();
}
return cloned;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -