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

📄 rectangularcake.java

📁 Java程序设计(美) David D. Riley著 机械工业出版社 书籍配套 代码
💻 JAVA
字号:
// Figure 9.9import java.awt.*;public class RectangularCake extends Cake  {    private	Rectangle theCake;		/**	post:	getX() == x  and  getY() == y	 *          and  getWidth() == w  and  getHeight() == h	 *          and  getBackground == Color.yellow 	 */    public RectangularCake( int x, int y, int w, int h )  {    	super(x, y, w, h);		setBackground( Color.yellow );	}	/**	post:	the cake is drawn as a rectangle filling the bounding rectangle	 *	   		and the color of the cake is getBackground() 	 */	protected void paintCake( Graphics g )   {		g.setColor( getBackground() );		g.fillRect(0, 0, getWidth(), getHeight());	}	/**	post:	two black lines (one vertical and one horizontal) divide 	 *						the cake into fourths	 *	   		and getWidth() > getHeight() implies the cake is separated by 	 *						two more vertical lines making 8 equal-sized pieces.	 *	   		and getWidth() <= getHeight() implies the cake is separated by 	 *						two more horizontal lines making 8 equal-sized pieces. 	 */	protected void paintEighthCuts( Graphics g )   {		g.setColor( Color.black );		g.drawLine(0, getHeight()/2, getWidth(), getHeight()/2);		g.drawLine(getWidth()/2, 0, getWidth()/2, getHeight());		if ( getWidth() > getHeight() )   {			g.drawLine(getWidth()/4, 0, getWidth()/4, getHeight());			g.drawLine(getWidth()*3/4, 0, getWidth()*3/4, getHeight());		} else {			g.drawLine(0, getHeight()/4, getWidth(), getHeight()/4);			g.drawLine(0, getHeight()*3/4, getWidth(), getHeight()*3/4);		}	}}

⌨️ 快捷键说明

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