Display.java
资源名称:ATM.zip [点击查看]
上传用户:ljt780218
上传日期:2022-07-30
资源大小:110k
文件大小:4k
源码类别:
金融证券系统
开发平台:
Java
- // <html><head><title>ATM Simulation Implementation - the Display</title></head><body><h2>ATM Simulation Implementation - the Display</h2><pre>
- /*
- * Example ATM simulation - file Display.java
- *
- * This file implements the class that manages the ATM's display
- *
- * Copyright (c) 1997 - Russell C. Bjork
- *
- */
- package atm.atmparts;
- import java.awt.*;
- import java.util.StringTokenizer;
- //</pre><hr><h3>Class Display</h3><pre>
- public class Display extends Panel
- {
- //</pre><hr><pre>
- public Display()
- { setLayout(new GridLayout(GUILayout.DISPLAYABLE_LINES, 1));
- setBackground(new Color(0, 96, 0)); // Dark green
- setForeground(Color.white);
- _line = new Label[GUILayout.DISPLAYABLE_LINES];
- for (int i = 0; i < GUILayout.DISPLAYABLE_LINES; i ++)
- { _line[i] = new Label("");
- add(_line[i]);
- }
- _currentLine = 0;
- }
- //</pre><hr><pre>
- public void requestCard()
- { write("Please insert your card to begin");
- }
- //</pre><hr><pre>
- public void requestPIN()
- { write(
- "Please enter your Personal Identification Number (PIN)n" +
- "Press ENTER when finished or CLEAR to start over");
- }
- //</pre><hr><pre>
- public void displayMenu(String whatToChoose,
- int numItems,
- String items[])
- { write(whatToChoose);
- for (int i = 0; i < numItems; i ++)
- write((i + 1) + ") " + items[i]);
- }
- //</pre><hr><pre>
- public void requestAmountEntry()
- { write(
- "Please enter amount.n" +
- "Press ENTER when finished or CLEAR to start over");
- }
- //</pre><hr><pre>
- public void requestDepositEnvelope()
- { write(
- "Please deposit an envelope in the slot");
- }
- //</pre><hr><pre>
- public void reportCardUnreadable()
- { write(
- "Sorry, your card was inserted incorrectly orn" +
- "is unreadable.n" +
- "Please try inserting your card again");
- }
- //</pre><hr><pre>
- public void reportTransactionFailure(String explanation)
- { write(explanation);
- write("n" +
- "Do you want to perform another transactionn" +
- "(1 = Yes, 2 = No)?");
- }
- //</pre><hr><pre>
- public void requestReEnterPIN()
- { write(
- "Your PIN was entered incorrectly.n" +
- "Please re-enter it");
- }
- //</pre><hr><pre>
- public void reportCardRetained()
- { write(
- "Your PIN was entered incorrectly.n" +
- "Your card has been retained - please contact the bank");
- try
- { Thread.sleep(10 * 1000); }
- catch (InterruptedException e)
- { }
- }
- //</pre><hr><pre>
- public void echoInput(String echo)
- { _line[GUILayout.DISPLAYABLE_LINES - 1].setText(" " + echo);
- }
- //</pre><hr><pre>
- public void clearDisplay()
- { for (int i = 0; i < GUILayout.DISPLAYABLE_LINES; i ++)
- _line[i].setText("");
- _currentLine = 0;
- }
- //</pre><hr><pre>
- // Private method and instance variables needed for GUI
- private void write(String s)
- // Write one or more lines; may contain multiple lines delimited by n
- { StringTokenizer t = new StringTokenizer(s, "n", false);
- while (t.hasMoreTokens())
- { try
- { _line[_currentLine ++].setText(t.nextToken()); }
- catch (Exception e)
- { }
- }
- }
- private Label _line[];
- private int _currentLine;
- }
- //</pre></body></html>