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

📄 useshapes.java

📁 用java画圆 用这个程序可以实现自动画图。
💻 JAVA
字号:
/*
 * Created on 2005-10-9
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package polymorphism;

/**
 * From 'Thinking in Java, 2nd ed.' by Bruce Eckel
 */
public class UseShapes {
	public static Shape randShape() {
		switch ((int) (Math.random() * 3)) {
		default:
		case 0:
			return new Circle();
		case 1:
			return new Square();
		case 2:
			return new Triangle();
		}
	}

	public static void main(String[] args) {
		Shape[] s = new Shape[9];
		// Fill up the array with shapes:
		for (int i = 0; i < s.length; i++)
			s[i] = randShape();
		// Make polymorphic method calls:
		for (int i = 0; i < s.length; i++)
			s[i].draw();
	}

}

⌨️ 快捷键说明

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