📄 simcardreader.java
字号:
/* * ATM Example system - file SimCardReader.java * * copyright (c) 2001 - Russell C. Bjork * */ package simulation;import atm.ATM;import banking.Card;import java.awt.*;import java.awt.event.*;/** Simulate the card reader */class SimCardReader extends Button{ /** Constructor * * @param simulation the Simulation object */ SimCardReader(final Simulation simulation) { super("Click to insert card"); addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { simulation.cardInserted(); } }); // Not available until machine is turned on setVisible(false); } /** Animate card going into the machine */ void animateInsertion() { originalBounds = getBounds(); Rectangle currentBounds = new Rectangle(originalBounds.x, originalBounds.y, originalBounds.width, originalBounds.height); while (currentBounds.width > 0 && currentBounds.height > 0) { setBounds(currentBounds.x, currentBounds.y, currentBounds.width, currentBounds.height); repaint(); try { Thread.sleep(100); } catch (InterruptedException e) { } currentBounds.height -= 1; currentBounds.width = (originalBounds.width * currentBounds.height) / originalBounds.height; currentBounds.x = originalBounds.x + (originalBounds.width - currentBounds.width) / 2; currentBounds.y = originalBounds.y + (originalBounds.height - currentBounds.height) / 2; } setVisible(false); } /** Animate ejecting the card that is currently inside the reader. */ void animateEjection() { setLabel("Ejecting card"); setVisible(true); Rectangle currentBounds = new Rectangle(originalBounds.x + originalBounds.width / 2, originalBounds.y + originalBounds.height / 2, originalBounds.width / originalBounds.height, 1); while (currentBounds.height <= originalBounds.height && currentBounds.width <= originalBounds.width) { setBounds(currentBounds.x, currentBounds.y, currentBounds.width, currentBounds.height); repaint(); try { Thread.sleep(100); } catch (InterruptedException e) { } currentBounds.height += 1; currentBounds.width = (originalBounds.width * currentBounds.height) / originalBounds.height; currentBounds.x = originalBounds.x + (originalBounds.width - currentBounds.width) / 2; currentBounds.y = originalBounds.y + (originalBounds.height - currentBounds.height) / 2; } setLabel("Click to insert card"); } /** Animate retaining the card that is currently inside the reader for action by the * bank. */ void animateRetention() { setLabel("Click to insert card"); setVisible(true); } /** To animate card insertion/ejection, we change the bounds of this button. * These are the original bounds we ultimately restore to */ private Rectangle originalBounds;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -