📄 atm.java
字号:
package src.cn.com.sun.atm;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class ATM extends WindowAdapter {
// fr.setBackground(Color.blue);颜色设置
Frame win1;
MenuBar myMenu;
Menu fileMenu;
Menu helpMenu;
Menu editMenu;
MenuItem fileMenuItem1;
MenuItem helpMenuItem1;
MenuItem editMenuItem1;
MyDialog dialog1;
TextField tx1;
TextField tx2;
Panel myP = new Panel();
Panel myP2 = new Panel();
Panel myP3 = new Panel();
Panel myP4 = new Panel();
Label logo;
Button btn1;
Button btn2;
Button btn3;
Button btn4;
Button btn5;
Button btn6;
String username;
int password;
boolean flag = false;
private static String defaultPath = System.getProperty("user.dir"); // 获取程序运行路径;
ATM() {
win1 = new Frame("升级版ATM系统");
win1.setLayout(new BorderLayout());
win1.setBackground(Color.blue);
// 设置菜单
myMenu = new MenuBar();
fileMenu = new Menu("File");
helpMenu = new Menu("Help");
editMenu = new Menu("Music");
myMenu.add(fileMenu);
myMenu.add(helpMenu);
myMenu.add(editMenu);
fileMenuItem1 = new MenuItem("Exit");
helpMenuItem1 = new MenuItem("About");
editMenuItem1 = new MenuItem("瓜娃子");
fileMenu.add(fileMenuItem1);
helpMenu.add(helpMenuItem1);
editMenu.add(editMenuItem1);
fileMenuItem1.addActionListener(new ActionListener1());
helpMenuItem1.addActionListener(new ActionListener1());
win1.setMenuBar(myMenu);
// 设置对话框(help菜单)
dialog1 = new MyDialog(win1, "关于升级版ATM系统", true);
dialog1.addWindowListener(this);
// /////////////////////////~~~~~~~~~~////////////////////////////////////////
Panel pp0 = new Panel();
pp0.setLayout(new FlowLayout());
Panel pp1 = new Panel();
pp1.setLayout(new FlowLayout());
// 用户名及密码
tx1 = new TextField(10);
tx2 = new TextField(10);
tx2.setEchoChar('*'); // 设置此文本字段的回送字符
// 设置各个Button
win1.add(myP, BorderLayout.NORTH);
myP.setLayout(new BorderLayout());
myP.add(pp0, BorderLayout.NORTH);
myP.add(pp1, BorderLayout.CENTER);
pp0.add(new Label("卡号:"));
pp0.add(tx1);
pp0.add(new Label("密码:"));
pp0.add(tx2);
btn1 = new Button("登陆");
btn2 = new Button("重置");
btn1.addActionListener(new ActionListener1());
btn2.addActionListener(new ActionListener1());
pp1.add(btn1);
pp1.add(btn2);
// /////////////////////////~~~~~~~~~~~////////////////////////////////////////
btn3 = new Button("账户余额");
btn3.setForeground(Color.black);
btn3.setBackground(Color.GRAY);
btn3.addActionListener(new ActionListener1());
btn4 = new Button("我要取款");
btn4.setForeground(Color.black);
btn4.setBackground(Color.BLUE);
btn4.addActionListener(new ActionListener1());
btn5 = new Button("修改密码");
btn5.setForeground(Color.black);
btn5.setBackground(Color.CYAN);
btn5.addActionListener(new ActionListener1());
btn6 = new Button("退出系统");
btn6.setForeground(Color.black);
btn6.setBackground(Color.LIGHT_GRAY);
btn6.addActionListener(new ActionListener1());
win1.add(myP2, BorderLayout.EAST);
myP2.setLayout(new GridLayout(4, 1));
myP2.add(btn3);
myP2.add(btn4);
myP2.add(btn5);
myP2.add(btn6);
// ///////////////////////////////////////////////////
Button btn00 = new Button("转账功能");
btn00.setForeground(Color.black);
btn00.setBackground(Color.LIGHT_GRAY);
Button btn01 = new Button("存钱到帐");
btn01.setForeground(Color.black);
btn01.setBackground(Color.CYAN);
Button btn02 = new Button("MP3视听");
btn02.setForeground(Color.black);
btn02.setBackground(Color.BLUE);
Button btn03 = new Button("其它服务");
btn03.setForeground(Color.black);
btn03.setBackground(Color.GRAY);
win1.add(myP3, BorderLayout.WEST);
myP3.setLayout(new GridLayout(4, 1));
myP3.add(btn00);
myP3.add(btn01);
myP3.add(btn02);
myP3.add(btn03);
// ////////////////////////////////////////////////////
// ////////////////////////////////////////////////////
JLabel labele = new JLabel();
java.net.URL imgURLE = ATM.class.getResource("wlcm.jpg");
labele.setIcon(new ImageIcon(imgURLE));
/**
* ImageIcon根据制定的图片创建一个图标 setIcon定义此组件要显示的图标
*/
myP4.add(labele);
win1.add(myP4, BorderLayout.CENTER);
win1.setVisible(true);
// ////////////////////////////////////////////////////
Panel myPP = new Panel();
win1.add(myPP, BorderLayout.SOUTH);
myPP.setLayout(new BorderLayout());
logo = new Label("Welcome to SiChuan Agricultural Bank!", Label.CENTER);
logo.setFont(new Font("Serif", Font.BOLD, 22));
Label logoo = new Label("Dinitial,All Rights Reserved", Label.CENTER);
logoo.setFont(new Font("Serif", Font.BOLD, 20));
myPP.add(logo, BorderLayout.NORTH);
myPP.add(logoo, BorderLayout.CENTER);
win1.add(myPP, BorderLayout.SOUTH);
win1.setSize(495,430);
win1.addWindowListener(this);
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
win1.setLocation((screenSize.width - 600) / 2,
(screenSize.height - 400) / 2);
win1.setVisible(true);
}
public static void main(String args[]) {
// 创建LOGO
JFrame f = new JFrame();
new WelcomeWindow("LOGO.jpg", f, 1500);
try {
Thread.sleep(3000);
} catch (Exception error) {
System.exit(1);
}
new ATM();
}
public void windowClosing(WindowEvent e) {
if (e.getSource() == win1) {
System.exit(0);
}
if (e.getSource() == dialog1) {
dialog1.dispose();
}
}
// 登陆
public void login(String name, int pword) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dburl = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="
+ defaultPath + "\\data\\data.mdb";
Connection con = DriverManager.getConnection(dburl, "", "");
CallableStatement cs = con.prepareCall("{call query1(?)}");
cs.setString(1, name);
ResultSet rs = cs.executeQuery();
while (rs.next()) {
long i = rs.getLong("password");
if (pword == i) {
flag = true;
myP.removeAll();
Panel pp = new Panel(new BorderLayout());
Label login = new Label("Congratulations to you~~",Label.CENTER);
login.setFont(new Font("Serif", Font.BOLD, 18));
Label loginn = new Label("Please do what you want!",Label.CENTER);
loginn.setFont(new Font("Serif", Font.BOLD, 16));
pp.add(login,BorderLayout.NORTH);
pp.add(loginn,BorderLayout.CENTER);
myP.add(pp);
// ////////////////////
// 登陆成功后显示的图片
myP4.removeAll();
JLabel la1 = new JLabel();
java.net.URL imgURLE = ATM.class.getResource("money.jpg");
la1.setIcon(new ImageIcon(imgURLE));
/**
* ImageIcon根据制定的图片创建一个图标 setIcon定义此组件要显示的图标
*/
myP4.add(la1);
win1.add(myP4, BorderLayout.CENTER);
win1.setVisible(true);
} else {
myP.removeAll();
myP4.removeAll();
Label jj = new Label("Sorry,你的密码或帐号错误!", Label.CENTER);
jj.setFont(new Font("Serif", Font.BOLD, 18));
jj.setForeground(Color.GRAY);
myP.add(jj, BorderLayout.NORTH);
// //////
// 登陆失败后显示的图片
JLabel la0 = new JLabel();
java.net.URL imgURLE = ATM.class.getResource("gwq.jpg");
la0.setIcon(new ImageIcon(imgURLE));
/**
* ImageIcon根据制定的图片创建一个图标 setIcon定义此组件要显示的图标
*/
myP4.add(la0);
win1.add(myP4, BorderLayout.CENTER);
win1.setVisible(true);
}
}
cs.close();
con.close();
} catch (SQLException e) {
System.out.println("SQLException caught");
} catch (ClassNotFoundException ex) {
System.out.println("error");
}
}
public void balance() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dburl = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="
+ defaultPath + "\\data\\data.mdb";
Connection con = DriverManager.getConnection(dburl, "", "");
CallableStatement cs = con.prepareCall("{call query1(?)}");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -