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

📄 nestedcircles.java

📁 Java程序设计(美) David D. Riley著 机械工业出版社 书籍配套 代码
💻 JAVA
字号:
// Figure 6.14import java.awt.Color;/**	Class Invariant *		A NestedCircles object... *			is a filled circular region, possibly with black,  *			concentric circles upon it   */public class NestedCircles  {	private Oval initialOval;	private int lastCircleRadius;	/** pre:	r > 0   <br>	 *	post:	A new black filled NestedCirle object is created 	 *				with upper-left corner at (x, y)   	 *			and  lastCircleRadius == r   	 */	public NestedCircles(int x, int y, int r)  {		initialOval = new Oval(x, y, 2*r, 2*r);		lastCircleRadius = r;	}	/** post:	result is this image suitable for passing as 	 *			an argument to add.  */	public Oval addableContent()   {		return initialOval;	}	/** pre:	c is a valid Color  <br>	 *	post:	initialOval is recolored using color c   	 */	public void setBackground(Color c)   {		initialOval.setBackground(c);		initialOval.repaint();	}	/** post:	lastCircleRadius == 0.8* lastCircleRadius@pre 	 *			and  a black circle with radius  of lastCircleRadius is	 *				 	added concentrically to this object 	 */	public void insertCircle()   {		Oval newOval, circleCenter;		int newX;		lastCircleRadius = (int)(lastCircleRadius *.8);		newX = (initialOval.getWidth() - 2*lastCircleRadius) / 2;		newOval = new Oval(newX, newX, 									2*lastCircleRadius, 2*lastCircleRadius);		initialOval.add(newOval, 0);		circleCenter = new Oval(1, 1, newOval.getWidth()-2,										 newOval.getHeight()-2);		circleCenter.setBackground( initialOval.getBackground() );		newOval.add(circleCenter, 0);		newOval.repaint();	}}

⌨️ 快捷键说明

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