📄 shapegenerator.java
字号:
import java.util.Random;
class ShapeGenerator {
public enum ShapeType { LINE, CIRCLE, SQUARE };
private Random rand = new Random();
private int size; // used to "keep" the shapes inside our drawing area (JPanel)
private ShapeType type;
public ShapeGenerator(int size){
this.size = size;
}
public void setShapeType( ShapeType shpType ){
type = shpType;
}
public Shape next( ) {
switch( type ) {
default:
case LINE: return new Line( rand.nextInt(size), rand.nextInt(size),
rand.nextInt(size), rand.nextInt(size) );
case CIRCLE : return new Circle(rand.nextInt(size), rand.nextInt(size),
rand.nextInt(size) / 2, rand.nextInt(size) / 2 );
case SQUARE: return new Square(rand.nextInt(size), rand.nextInt(size),
rand.nextInt(size) / 2, rand.nextInt(size) / 2 );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -