CashDispenser.java
资源名称:ATM.zip [点击查看]
上传用户:ljt780218
上传日期:2022-07-30
资源大小:110k
文件大小:2k
源码类别:
金融证券系统
开发平台:
Java
- // <html><head><title>ATM Simulation Implementation - the Cash Dispenser</title></head><body><h2>ATM Simulation Implementation - the Cash Dispenser</h2><pre>
- /*
- * Example ATM simulation - file CashDispenser.java
- *
- * This file implements the class that manages the ATM's cash dispenser
- *
- * Copyright (c) 1997 - Russell C. Bjork
- *
- */
- package atm.atmparts;
- import java.awt.*;
- import atm.util.Money;
- //</pre><hr><h3>Class CashDispenser</h3><pre>
- public class CashDispenser extends Panel
- {
- //</pre><hr><pre>
- public CashDispenser()
- { setLayout(new GridLayout(1,1));
- _label = new Label("$XXX", Label.CENTER);
- _label.setFont(new Font("Helvetica", Font.PLAIN, 24));
- _label.setForeground(new Color(0, 64, 0));
- add(_label);
- _label.hide();
- _currentCash = new Money(0);
- }
- //</pre><hr><pre>
- public void setCash(Money initialCash)
- { _currentCash = initialCash;
- }
- //</pre><hr><pre>
- public void dispenseCash(Money amount)
- { _label.setText("$" + amount.dollars());
- for (int size = 3; size <= 24; size += 1)
- { _label.setFont(new Font("Helvetica", Font.PLAIN, size));
- _label.show();
- try
- { Thread.sleep(250); }
- catch (InterruptedException e)
- { }
- _label.hide();
- }
- _currentCash.subtract(amount);
- }
- //</pre><hr><pre>
- public Money currentCash()
- { return _currentCash;
- }
- //</pre><hr><pre>
- // Instance variable
- private Money _currentCash;
- //</pre><hr><pre>
- // This field is needed for the GUI
- private Label _label;
- }
- //</pre></body></html>