shapegenerator.java
来自「能够画线条、圆和长方形的Java程序」· Java 代码 · 共 30 行
JAVA
30 行
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 + =
减小字号Ctrl + -
显示快捷键?