mm.text文件中存放资源
name=java
password=1995
money=6000
======================================
实现代码
package com.cement;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Properties;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class ATM {
public static Properties zhmm = new Properties();
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "欢迎光临");
// 调用读取密码文档
dq();
for (int i = 0; i < 3; i++){
String namstr = JOptionPane.showInputDialog(null, "输入用户名");
String pwdstr = JOptionPane.showInputDialog(null, "请输入密码");
int m = Integer.parseInt(pwdstr);
//三次输入密码循环
if (namstr.equals(zhmm.getProperty("name"))
&& pwdstr.equals(zhmm.getProperty("password"))) {
// 调用主界面方法
zjm();
} else {
JOptionPane.showMessageDialog(null, "用户名或密码错误");
}
}
JOptionPane.showMessageDialog(null, "非法用户");
System.exit(0);
}
// 主界面方法
public static void zjm() {
while (true) {
String xz = JOptionPane.showInputDialog(null,
"1、存款
2、取款
3、查询
4、改密
5、退出");
int x = Integer.parseInt(xz);
switch (x) {
case 1:
ck();
break;
case 2:
qk();
break;
case 3:
cx();
break;
case 4:
gm();
break;
case 5:
System.exit(0);
}
}
}
public static void gm() {
String str = JOptionPane.showInputDialog(null, "输入新密码");
String stri = JOptionPane.showInputDialog(null, "再次输入");
int pwd1 = Integer.parseInt(str);
int pwd2 = Integer.parseInt(stri);
if (pwd1 == pwd2) {
zhmm.setProperty("password", pwd1 + "");
JOptionPane.showMessageDialog(null, "修改成功");
lr();
} else {
JOptionPane.showMessageDialog(null, "输入密码不一致");
}
}
// 查询
public static void cx() {
JOptionPane.showMessageDialog(null, zhmm.getProperty("money"));
}
// 1存款方法
public static void ck() {
String money = JOptionPane.showInputDialog(null, "输入存款金额");
int m1 = Integer.parseInt(money);
int m2 = Integer.parseInt(zhmm.getProperty("money"));
m2 = m1 + m2;
zhmm.setProperty("money", m2 + "");
}
// 2取款方法
public static void qk() {
String money = JOptionPane.showInputDialog(null, "输入取款金额");
int m1 = Integer.parseInt(money);
int newm = Integer.parseInt(zhmm.getProperty("money"));
if (newm > m1&&m1<=10000) {
newm = newm - m1;
zhmm.setProperty("money", newm + "");
} else {
JOptionPane.showMessageDialog(null, "输入金额不正确");
}
}
// 读取用户名和密码方法
public static void dq() {
try {
zhmm.load(new FileReader("file\mm.txt"));
} catch (Exception e) {
System.out.print("顶顶顶顶顶顶顶");
}
}
// 录入修改数据
public static void lr() {
try {
zhmm.store(new FileWriter("file\mm.txt"), null);
} catch (Exception e) {
System.out.print("顶顶顶顶顶顶顶");
}
}
}