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

📄 circularcake.java

📁 Java程序设计(美) David D. Riley著 机械工业出版社 书籍配套 代码
💻 JAVA
字号:
// Figure 9.10import java.awt.*;public class CircularCake  extends Cake  {		/**	post:	getX() == x  and   getY() == y	 *			and  getWidth() == getHeight() == d	 *			and   getBackground() == Color.pink  	 */    public CircularCake( int x, int y, int d )  {    	super(x, y, d, d);		setBackground( Color.pink );	}	/**	post:	the cake is drawm as an oval filling the bounding rectangle	 *	   		and the color of the cake is getBackground() 	 */	protected void paintCake( Graphics g )   {		g.setColor( getBackground() );		g.fillOval(0, 0, getWidth(), getHeight());	}	/**	post:   four black lines are drawn through the cake center to form	 *          eight wedge-shaped pieces of equal size.  	 */	protected void paintEighthCuts( Graphics g )   {		int ds, dl;		g.setColor( Color.black );		// draw horizontal and vertical lines, respectively		g.drawLine(0, getHeight()/2, getWidth(), getHeight()/2);		g.drawLine(getWidth()/2, 0, getWidth()/2, getHeight() );        		// draw diagonal lines		ds = (int)( (getWidth() - getWidth()/Math.sqrt(2.0)) / 2.0 );		dl = (int)( getWidth() / Math.sqrt(2.0) ) + ds;		g.drawLine( ds, ds, dl, dl );		g.drawLine( ds, dl, dl, ds );	}}

⌨️ 快捷键说明

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