OperatorPanel.java
资源名称:ATM.zip [点击查看]
上传用户:ljt780218
上传日期:2022-07-30
资源大小:110k
文件大小:2k
源码类别:
金融证券系统
开发平台:
Java
- // <html><head><title>ATM Simulation Implementation - the Operator Panel</title></head><body><h2>ATM Simulation Implementation - the Operator Panel</h2><pre>
- /*
- * Example ATM simulation - file OperatorPanel.java
- *
- * This file implements the class that manages the ATM's operator panel
- *
- * Copyright (c) 1997 - Russell C. Bjork
- *
- */
- package atm.atmparts;
- import java.awt.*;
- import atm.util.Money;
- //</pre><hr><h3>Class OperatorPanel</h3><pre>
- public class OperatorPanel extends Panel
- {
- //</pre><hr><pre>
- public OperatorPanel()
- { setLayout(new BorderLayout());
- setBackground(new Color(128,128,255));
- add("West", new Label("Operator Panel"));
- _message = new Label("Click ON button to turn ATM on");
- add("Center", _message);
- CheckboxGroup group = new CheckboxGroup();
- _offButton = new Checkbox("OFF", group, true);
- _onButton = new Checkbox("ON", group, false);
- Panel buttonPanel = new Panel();
- buttonPanel.add(_offButton);
- buttonPanel.add(_onButton);
- add("East", buttonPanel);
- }
- //</pre><hr><pre>
- public synchronized boolean switchOn()
- { // This will blink the "Click ON button ..." message when
- // the ATM is off
- boolean isOn = _onButton.getState();
- if (! isOn)
- if (_message.isShowing())
- _message.hide();
- else
- _message.show();
- else
- _message.hide();
- return isOn;
- }
- //</pre><hr><pre>
- public Money getInitialCash()
- {
- int numberBills = -1;
- while (numberBills < 0)
- { QuestionDialog cashDialog = new
- QuestionDialog("How many $20 bills are in the cash dispenser?", this);
- String answer = cashDialog.answer();
- if (answer != null)
- try
- { numberBills = Integer.parseInt(answer); }
- catch (NumberFormatException e)
- { }
- }
- return new Money(20 * numberBills);
- }
- //</pre><hr><pre>
- // These fields are needed by the GUI
- private Label _message;
- private Checkbox _offButton;
- private Checkbox _onButton;
- }
- //</pre></body></html>