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

📄 driver.java

📁 Java程序设计(美) David D. Riley著 机械工业出版社 书籍配套 代码
💻 JAVA
字号:
import java.awt.*;/**	Money Test Program using Labels  (Figure 6.33) *	Author: David Riley */public class Driver extends ThreeButtons {	private	Label dollarLabel, quarterLabel;	private	Label dimeLabel, nickelLabel;	private MoneyUSA money;	private ThreeButtonFrame  theWin;	/**	post:	A window is displays monetary denominations. */	public Driver()   {		theWin = new ThreeButtonFrame("Money Counter");		theWin.setLayout(null);		dollarLabel = newlyAddedLabel(10);		quarterLabel = newlyAddedLabel(50);		dimeLabel = newlyAddedLabel(90);		nickelLabel = newlyAddedLabel(130);		money = new MoneyUSA(0, 0, 0, 0, 0);		updateDisplay();	}	/** post:	result is displayed upon theWin誷 content pane	 *			and  result.getX()==100  and  result.getY()==y	 *			and  result.getWidth()==100  and  result.getHeight()==30 	 */	public Label newlyAddedLabel(int y)   {		Label result;		result = new Label();		result.setBounds(100, y, 100, 30);		theWin.add(result, 0);		return result;	}	/** pre:	money is instantiated	 *	post:	money.dollars == money.dollars@pre + 1  	 */	public void leftAction()   {		money.dollars++;		updateDisplay();	}		/**	pre:	money is instantiated	 *	post:	money.quarters == money.quarters@pre + 1	 *			and  money.nickels == money.nickels@pre + 3  	 */	public void midAction()   {		money.quarters++;		money.nickels = money.nickels + 3;		updateDisplay();	}		/**	pre:	money is instantiated	 *	post:	money.valueInCents == money.valueInCents@pre	 *			and money consolidated into largest possible denominations  	 */	public void rightAction()   {		money.consolidate();		updateDisplay();	}	/** pre:	money is instantiated	 *	post:	the output labels are updated to reflect the	 *			value of dollars, quarters, dimes, and nickels of	 *			the money variable  	 */	private void updateDisplay()   {		dollarLabel.setText( "Dollars: " + money.dollars );		dollarLabel.repaint();		quarterLabel.setText( "Quarters: " + money.quarters );		quarterLabel.repaint();		dimeLabel.setText( "Dimes: " + money.dimes );		dimeLabel.repaint();		nickelLabel.setText( "Nickels: " + money.nickels );		nickelLabel.repaint();	}}

⌨️ 快捷键说明

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