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

📄 driver.java

📁 Java程序设计(美) David D. Riley著 机械工业出版社 书籍配套 代码
💻 JAVA
字号:
import javax.swing.JFrame;/** Driver for cake cutting  (Figures 9.9, 9.10, 9.12, 9.13, and 9.18) *  Author: David D. Riley *  Date: January, 2005 */public class Driver  {    private JFrame  window;    private Cake theCake;    private CakeButton sliceButton;	/**	post:	window is created at (10, 10) with width and height of 400	 *				and  sliceButton is added to window	 *				and  theCake is constructed as a CircularCake object   	 */    public Driver()  {		window = new JFrame("Cake Cutter");		window.setBounds(10, 10, 400, 500);		window.setVisible(true);		window.setLayout(null);		theCake = new CircularCake(100, 100, 200);		window.add( theCake, 0 );		sliceButton = new CakeButton( 75, 5, this);		window.add( sliceButton, 0 );		window.repaint();    }    	/**	pre:	theCake != null  <br>     *		post:	theCake@pre is removed from window	 *  			and  a new theCake is constructed & placed on window	 *			 	(The new cake has a 50-50 chance of being circular 	 *				or rectangular.	 */	public  void  cutTheCake()   {		window.remove(theCake);    	if (Math.random() > 0.5)   {			theCake = new CircularCake(100, 100, (int)(Math.random()*200+1));    	} else {    		theCake = new RectangularCake(100, 150, 200, (int)(Math.random()*300+1));    	}    	window.add( theCake, 0 );		window.repaint();    }}

⌨️ 快捷键说明

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