⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shapegenerator.java

📁 能够画线条、圆和长方形的Java程序
💻 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 + -