// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name: SimKeyboard.java
package simulation;
import java.awt.*;
import java.awt.event.*;
// Referenced classes of package simulation:
// SimDisplay, Simulation, SimEnvelopeAcceptor
class SimKeyboard extends Panel
{
private SimDisplay display;
private SimEnvelopeAcceptor envelopeAcceptor;
private int mode;
private static final int IDLE_MODE = 0;
private static final int PIN_MODE = 1;
private static final int AMOUNT_MODE = 2;
private static final int MENU_MODE = 3;
private StringBuffer currentInput;
private boolean cancelled;
private int maxValue;
SimKeyboard(SimDisplay simdisplay, SimEnvelopeAcceptor simenvelopeacceptor)
{
display = simdisplay;
envelopeAcceptor = simenvelopeacceptor;
setLayout(new GridLayout(5, 3));
Button abutton[] = new Button[10];
for(int i = 1; i < 10; i++)
{
abutton[i] = new Button(String.valueOf(i));
add(abutton[i]);
}
add(new Label(""));
abutton[0] = new Button("0");
add(abutton[0]);
add(new Label(""));
Button button = new Button("ENTER");
button.setForeground(Color.black);
button.setBackground(new Color(128, 128, 255));
add(button);
Button button1 = new Button("CLEAR");
button1.setForeground(Color.black);
button1.setBackground(new Color(255, 128, 128));
add(button1);
Button button2 = new Button("CANCEL");
button2.setBackground(Color.red);
button2.setForeground(Color.black);
add(button2);
for(int j = 0; j < 10; j++)
abutton[j].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionevent)
{
digitKeyPressed(Integer.parseInt(actionevent.getActionCommand()));
}
});
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionevent)
{
enterKeyPressed();
}
});
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionevent)
{
clearKeyPressed();
}
});
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionevent)
{
cancelKeyPressed();
}
});
addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent keyevent)
{
char c = keyevent.getKeyChar();
int k = keyevent.getKeyCode();
if(c >= '0' && c <= '9')
{
digitKeyPressed(c - 48);
keyevent.consume();
return;
}
switch(k)
{
case 10: // '\n'
enterKeyPressed();
break;
case 12: // '\f'
clearKeyPressed();
break;
case 3: // '\003'
case 27: // '\033'
cancelKeyPressed();
break;
}
keyevent.consume();
}
});
currentInput = new StringBuffer();
mode = 0;
}
synchronized String readInput(int i, int j)
{
mode = i;
maxValue = j;
currentInput.setLength(0);
cancelled = false;
if(i == 2)
setEcho("0.00");
else
setEcho("");
requestFocus();
try
{
wait();
}
catch(InterruptedException _ex) { }
mode = 0;
if(cancelled)
return null;
else
return currentInput.toString();
}
private synchronized void digitKeyPressed(int i)
{
switch(mode)
{
case 1: // '\001'
currentInput.append(i);
StringBuffer stringbuffer = new StringBuffer();
for(int j = 0; j < currentInput.length(); j++)
stringbuffer.append('*');
setEcho(stringbuffer.toString());
return;
case 2: // '\002'
currentInput.append(i);
String s = currentInput.toString();
if(s.length() == 1)
{
setEcho("0.0" + s);
return;
}
if(s.length() == 2)
{
setEcho("0." + s);
return;
} else
{
setEcho(s.substring(0, s.length() - 2) + "." + s.substring(s.length() - 2));
return;
}
case 3: // '\003'
if(i > 0 && i <= maxValue)
{
currentInput.append(i);
notify();
return;
} else
{
getToolkit().beep();
return;
}
case 0: // '\0'
default:
return;
}
}
private synchronized void enterKeyPressed()
{
switch(mode)
{
case 1: // '\001'
case 2: // '\002'
if(currentInput.length() > 0)
{
notify();
return;
} else
{
getToolkit().beep();
return;
}
case 3: // '\003'
getToolkit().beep();
return;
case 0: // '\0'
default:
return;
}
}
private synchronized void clearKeyPressed()
{
switch(mode)
{
case 1: // '\001'
currentInput.setLength(0);
setEcho("");
return;
case 2: // '\002'
currentInput.setLength(0);
setEcho("0.00");
return;
case 3: // '\003'
getToolkit().beep();
return;
case 0: // '\0'
default:
return;
}
}
private synchronized void cancelKeyPressed()
{
switch(mode)
{
case 0: // '\0'
synchronized(envelopeAcceptor)
{
envelopeAcceptor.notify();
}
// fall through
case 1: // '\001'
case 2: // '\002'
case 3: // '\003'
cancelled = true;
notify();
// fall through
default:
return;
}
}
private void setEcho(String s)
{
display.setEcho(s);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
ATM机模拟_JAVA实现_JAVA初学者最好的案例
共106个文件
class:65个
java:38个
classpath:1个
需积分: 10 13 下载量 196 浏览量
2008-10-08
21:33:28
上传
评论
收藏 88KB RAR 举报
温馨提示
ATM机模拟_JAVA实现_JAVA初学者最好的案例 这是我高三的时候做的,基本功能都实现了,连上了数据库。。感觉还不错。。有兴趣的可以下载来看看。
资源推荐
资源详情
资源评论
收起资源包目录
ATM机模拟_JAVA实现_JAVA初学者最好的案例 (106个子文件)
java.policy.applet 141B
Transaction.class 5KB
SimKeyboard.class 5KB
ATM.class 4KB
Simulation.class 4KB
ATMPanel.class 4KB
SimulatedBank.class 4KB
GUI.class 3KB
Message.class 3KB
Withdrawal.class 3KB
LogPanel.class 3KB
SimDisplay.class 2KB
SimReceiptPrinter.class 2KB
Deposit.class 2KB
BillsPanel.class 2KB
Session.class 2KB
CardPanel.class 2KB
Transfer.class 2KB
ATMMain.class 2KB
Receipt.class 2KB
SimCardReader.class 2KB
CustomerConsole.class 2KB
SimEnvelopeAcceptor.class 2KB
Inquiry.class 2KB
SimOperatorPanel.class 2KB
Transfer$1.class 1KB
SimOperatorPanel$1.class 1KB
Withdrawal$1.class 1KB
SimCashDispenser.class 1KB
Deposit$1.class 1KB
Log.class 1KB
Money.class 1KB
Inquiry$1.class 1KB
NetworkToBank.class 1KB
SimOperatorPanel$2.class 1KB
Receipt$1.class 1KB
SimKeyboard$5.class 1KB
CashDispenser.class 1KB
ATMApplet.class 999B
SimReceiptPrinter$1.class 994B
SimKeyboard$1.class 877B
ReceiptPrinter.class 850B
SimEnvelopeAcceptor$1.class 844B
SimCardReader$1.class 795B
LogPanel$1.class 792B
LogPanel$2.class 773B
ATMPanel$1.class 773B
EnvelopeAcceptor.class 756B
CardReader.class 723B
SimulatedBank$Failure.class 717B
BillsPanel$1.class 691B
Status.class 691B
SimKeyboard$2.class 687B
SimKeyboard$4.class 687B
SimKeyboard$3.class 687B
CardPanel$1.class 686B
Balances.class 673B
AccountInformation.class 620B
SimulatedBank$Success.class 618B
OperatorPanel.class 560B
ATMMain$1.class 540B
SimulatedBank$InvalidPIN.class 524B
ATMMain$2.class 513B
Transaction$CardRetained.class 476B
CustomerConsole$Cancelled.class 453B
Card.class 397B
.classpath 226B
SimKeyboard.java 7KB
Transaction.java 7KB
SimulatedBank.java 6KB
ATM.java 5KB
ATMPanel.java 5KB
Simulation.java 4KB
Session.java 3KB
SimCardReader.java 3KB
GUI.java 3KB
Message.java 3KB
Receipt.java 2KB
BillsPanel.java 2KB
LogPanel.java 2KB
CustomerConsole.java 2KB
SimEnvelopeAcceptor.java 2KB
SimOperatorPanel.java 2KB
Withdrawal.java 2KB
CardPanel.java 2KB
SimDisplay.java 2KB
Transfer.java 2KB
Deposit.java 2KB
SimReceiptPrinter.java 2KB
ATMMain.java 1KB
Inquiry.java 1KB
SimCashDispenser.java 1KB
NetworkToBank.java 1006B
CashDispenser.java 982B
Money.java 954B
Log.java 926B
EnvelopeAcceptor.java 851B
ATMApplet.java 794B
CardReader.java 747B
Balances.java 723B
共 106 条
- 1
- 2
资源评论
bazhong
- 粉丝: 190
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功