📄 myframe.java
字号:
package com.gaoying.view;
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.LineBorder;
import com.gaoying.controler.CardListener;
import com.gaoying.controler.ComiListener;
import com.gaoying.controler.NumListener;
import com.gaoying.controler.ViewListener;
import com.gaoying.model.Account;
import com.gaoying.util.FileInOut;
public class Myframe extends JFrame {
private JButton viewBut[];
private JButton moneyBut,cardBut;
private JButton numBut[];
private JButton opBut[];
private JPanel top,viewpan,bottom,opPan;
private JTextField fd;
private JLabel lab[];
private int select=0;//-1吞卡 0欢迎界面 1输入密码 2 操作界面
//3取款界面 4查询界面 5修改密码 6 转账 7取卡
private Account acc[];
private int index;
private int count=0;
private int ccount=0;
private JPasswordField pas;
public Myframe(){
super("ATM");
acc=FileInOut.readAllAcc();
this.setBounds(200,200,400,550);
this.setLayout(null);
top=new JPanel();
top.setBounds(5,5,380,160);
top.setBorder(new LineBorder(Color.BLACK));
top.setLayout(null);
this.add(top);
viewBut=new JButton[8];
for(int i=0;i<viewBut.length;i++){
if(i<4){
viewBut[i]=new JButton("==>>");
viewBut[i].setBounds(5,5+i*40,80,30);
}else{
viewBut[i]=new JButton("<<==");
viewBut[i].setBounds(295,5+(i-4)*40,80,30);
}
top.add(viewBut[i]);
}
viewpan=new JPanel();
viewpan.setBounds(90,5,200,150);
viewpan.setBackground(Color.BLUE);
top.add(viewpan);
//中间按钮
moneyBut=new JButton("|________取钱处_______|");
moneyBut.setBounds(8,175,230,50);
this.add(moneyBut);
cardBut=new JButton("|____插卡处____|");
cardBut.setBounds(248,175,135,50);
this.add(cardBut);
//操作台
bottom=new JPanel();
bottom.setBounds(5,235,380,240);
bottom.setBorder(new LineBorder(Color.BLACK));
bottom.setLayout(null);
this.add(bottom);
opPan=new JPanel();
opPan.setBounds(5,5,230,230);
opPan.setLayout(new GridLayout(4,3,10,10));
bottom.add(opPan);
numBut=new JButton[12];
String name[]={"7","8","9","4","5","6","1","2","3","0","00","."};
for(int i=0;i<numBut.length;i++){
numBut[i]=new JButton(name[i]);
opPan.add(numBut[i]);
}
opBut=new JButton[3];
opBut[0]=new JButton("更正");
opBut[0].setBounds(255,35,105,50);
opBut[1]=new JButton("取消");
opBut[1].setBounds(255,105,105,50);
opBut[2]=new JButton("确认");
opBut[2].setBounds(255,175,105,50);
bottom.add(opBut[0]);
bottom.add(opBut[1]);
bottom.add(opBut[2]);
//屏幕标签
lab=new JLabel[9];
name=new String[]{"取款","查询","修改密码","取卡","转账","返回","是","否","欢迎使用,请插卡","附加"};
viewpan.setLayout(null);
for(int i=0;i<lab.length;i++){
lab[i]=new JLabel(name[i]);
if(i<4){
lab[i].setBounds(2,40*i,100,30);
lab[i].setHorizontalAlignment(JLabel.LEFT);
}else if(i<8){
lab[i].setBounds(98,40*(i-4),100,30);
lab[i].setHorizontalAlignment(JLabel.RIGHT);
}else{
lab[i].setBounds(0,50,200,30);
lab[i].setHorizontalAlignment(JLabel.CENTER);
}
lab[i].setForeground(Color.WHITE);
viewpan.add(lab[i]);
}
fd=new JTextField();
fd.setBounds(30,110,140,30);
viewpan.add(fd);
//密码文本框
pas=new JPasswordField();
pas.setBounds(30,110,140,30);
viewpan.add(pas);
pas.setEchoChar('*');
pas.setVisible(false);
setView();
//添加监听器
cardBut.addActionListener(new CardListener(this));
//數字監聽器
for(int i=0;i<numBut.length;i++){
numBut[i].addActionListener(new NumListener(this));
}
//確定監聽器
opBut[2].addActionListener(new ComiListener(this));
//取消监听器
opBut[1].addActionListener(new ComiListener(this));
//更正监听器
opBut[0].addActionListener(new ComiListener(this));
//按钮监听器
for(int i=0;i<viewBut.length;i++){
viewBut[i].addActionListener(new ViewListener(this));
}
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void setView(){
boolean flag[];
switch(select){
case -1://吞卡
flag=new boolean[]{false,false,false,false,false,false,false,false,true};
view(flag,false);
this.getLab()[8].setText("吞卡,请与银行联系");
break;
case 0://欢迎界面
flag=new boolean[]{false,false,false,false,false,false,false,false,true};
view(flag,false);
break;
case 1://输入密码界面
flag=new boolean[]{false,false,false,false,false,false,false,false,true};
view(flag,false);
getPas().setVisible(true);
this.getLab()[8].setText("请输入密码:");
break;
case 2://操作界面
this.getLab()[8].setText(null);
flag=new boolean[]{true,true,true,true,true,true,false,false,true};
view(flag,false);
break;
case 3://取款界面
flag=new boolean[]{false,false,false,false,false,false,false,false,true};
view(flag,true);
this.getLab()[8].setText("请输入取款金额:");
break;
case 4://查询界面
flag=new boolean[]{false,false,false,false,false,true,false,false,true};
view(flag,false);
this.getLab()[8].setText("余额:"+acc[index].getMoney());
break;
case 5://修改密码界面
flag=new boolean[]{false,false,false,false,false,true,false,false,true};
view(flag,false);
getPas().setVisible(true);
this.getLab()[8].setText("请输入新密码:");
break;
case 6://转账界面
getPas().setVisible(false);
flag=new boolean[]{false,false,false,false,false,true,false,false,true};
view(flag,true);
this.getLab()[8].setText("请输入转账账号:");
break;
case 7://取卡界面
getPas().setVisible(false);
flag=new boolean[]{false,false,false,false,false,false,true,true,true};
view(flag,false);
this.getLab()[8].setText("是否打印凭条:");
break;
}
}
public void view(boolean flag[],boolean fd){
for(int i=0;i<flag.length;i++){
lab[i].setVisible(flag[i]);
}
this.fd.setVisible(fd);
}
public JButton[] getViewBut() {
return viewBut;
}
public void setViewBut(JButton[] viewBut) {
this.viewBut = viewBut;
}
public JButton getMoneyBut() {
return moneyBut;
}
public void setMoneyBut(JButton moneyBut) {
this.moneyBut = moneyBut;
}
public JButton getCardBut() {
return cardBut;
}
public void setCardBut(JButton cardBut) {
this.cardBut = cardBut;
}
public JButton[] getNumBut() {
return numBut;
}
public void setNumBut(JButton[] numBut) {
this.numBut = numBut;
}
public JButton[] getOpBut() {
return opBut;
}
public void setOpBut(JButton[] opBut) {
this.opBut = opBut;
}
public JPanel getTop() {
return top;
}
public void setTop(JPanel top) {
this.top = top;
}
public int getCcount() {
return ccount;
}
public void setCcount(int ccount) {
this.ccount = ccount;
}
public JPanel getViewpan() {
return viewpan;
}
public void setViewpan(JPanel viewpan) {
this.viewpan = viewpan;
}
public JPanel getBottom() {
return bottom;
}
public void setBottom(JPanel bottom) {
this.bottom = bottom;
}
public JPanel getOpPan() {
return opPan;
}
public void setOpPan(JPanel opPan) {
this.opPan = opPan;
}
public JTextField getFd() {
return fd;
}
public void setFd(JTextField fd) {
this.fd = fd;
}
public JLabel[] getLab() {
return lab;
}
public void setLab(JLabel[] lab) {
this.lab = lab;
}
public int getSelect() {
return select;
}
public void setSelect(int select) {
this.select = select;
}
public Account[] getAcc() {
return acc;
}
public void setAcc(Account[] acc) {
this.acc = acc;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public JPasswordField getPas() {
return pas;
}
public void setPas(JPasswordField pas) {
this.pas = pas;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
//得到指定卡号的位置
public int cardIndexOf(String Card){
for(int i=0;i<acc.length;i++){
if(acc[i].getCardnum().equals(Card)){
return i;
}
}
return -1;
}
//驗證密碼是否正確
public boolean ifPassword(String password){
if(acc[index].getPassword().equals(String.valueOf(password))){
return true;
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -