Java Swing(GUI窗口)+ Mysql,ATM机简易功能的实现

ATM登录功能:

package test;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.awt.event.ActionEvent;
import java.awt.Component;
import javax.swing.Box;
import java.awt.Panel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import java.awt.Frame;
import javax.swing.JTextField;
import javax.swing.JTable;
import javax.swing.JTextPane;
import javax.swing.border.TitledBorder;
import javax.swing.border.EtchedBorder;
import java.awt.Color;
import javax.swing.JPasswordField;
import java.awt.Toolkit;
import javax.swing.ImageIcon;


public class ATMLogin extends JFrame {
	
	private JPanel contentPane;
	private JTextField textField;
	private JPasswordField passwordField;
	

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ATMLogin frame = new ATMLogin();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 * @param name2 
	 */
	public ATMLogin() {
		setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\JAVA\\My\\\u56FE\u6807\\ConstructionBank.jpg"));
		
		setBackground(new Color(255, 255, 255));
		setTitle("\u6B22\u8FCE\u4F7F\u7528\u94F6\u884CATM\u673A");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 907, 513);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(255, 255, 255));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JButton btnNewButton = new JButton("");
		btnNewButton.setBounds(10, 57, 107, 45);
		contentPane.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("");
		btnNewButton_1.setBounds(10, 168, 107, 45);
		contentPane.add(btnNewButton_1);
		
		JButton btnNewButton_2 = new JButton("\u6CE8\u518C");
		btnNewButton_2.setToolTipText("");
		btnNewButton_2.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Enrolled frame1 = new Enrolled();
				frame1.setVisible(true);
			}
		});
		btnNewButton_2.setBounds(10, 280, 107, 45);
		contentPane.add(btnNewButton_2);
		
		JButton btnNewButton_3 = new JButton("\u53D6\u6D88");
		btnNewButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				textField.setText(null);
				passwordField.setText(null);
			}
		});
		btnNewButton_3.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_3.setBounds(10, 392, 107, 45);
		contentPane.add(btnNewButton_3);
		
		JButton btnNewButton_4 = new JButton("");
		btnNewButton_4.setBounds(775, 57, 107, 45);
		contentPane.add(btnNewButton_4);
		
		JButton btnNewButton_1_1 = new JButton("");
		btnNewButton_1_1.setBounds(775, 168, 107, 45);
		contentPane.add(btnNewButton_1_1);
		
		JButton btnNewButton_2_1 = new JButton("");
		btnNewButton_2_1.setBounds(775, 280, 107, 45);
		contentPane.add(btnNewButton_2_1);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBackground(new Color(255, 255, 255));
		panel_1.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(255, 255, 255), new Color(160, 160, 160)), "\u767B\u9646\u7A97\u53E3", TitledBorder.CENTER, TitledBorder.TOP,new Font("楷体", Font.PLAIN, 20), new Color(255, 0, 0)));
		panel_1.setBounds(127, 10, 638, 440);
		contentPane.add(panel_1);
		panel_1.setLayout(null);
		
		Panel panel = new Panel();
		panel.setBackground(new Color(255, 255, 255));
		panel.setBounds(10, 24, 618, 406);
		panel_1.add(panel);
		panel.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("\u8D26\u53F7\uFF1A");
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 20));
		lblNewLabel.setBounds(135, 88, 78, 44);
		panel.add(lblNewLabel);
		
		JLabel lblNewLabel_2 = new JLabel("\u5BC6\u7801\uFF1A");
		lblNewLabel_2.setFont(new Font("宋体", Font.PLAIN, 20));
		lblNewLabel_2.setBounds(135, 190, 78, 44);
		panel.add(lblNewLabel_2);
		
		textField = new JTextField();
		textField.setFont(new Font("宋体", Font.PLAIN, 20));
		textField.setBounds(242, 91, 253, 44);
		panel.add(textField);
		textField.setColumns(10);
		
		passwordField = new JPasswordField();
		passwordField.setFont(new Font("宋体", Font.PLAIN, 20));
		passwordField.setEchoChar('*');
		passwordField.setBounds(242, 193, 253, 44);
		panel.add(passwordField);
		
		JButton btnNewButton_3_1 = new JButton("\u786E\u8BA4");
		btnNewButton_3_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
				String sql2 = "select * from atm where binary name ="+"'"+textField.getText()+"'"+"and binary password="+"'"+passwordField.getText()+"'";
				DBHelper dbHelper = new DBHelper();
				ResultSet rsResultSet = dbHelper.DB(sql2);//使用数据库判断该账号账号及密码是否对应
				if(rsResultSet.next()==true){
					JOptionPane.showMessageDialog(passwordField, "登录成功!", "提示:",JOptionPane.WARNING_MESSAGE);
					dbHelper.downConn();
					
					Mainwindow frame1 =new Mainwindow(textField.getText());
					frame1.setVisible(true);
					
//					if(textField.getText().matches("[a-zA-Z_0-9]{6,15}")) {
//						System.out.print("yes");
//					}
//					else {
//						System.out.print("no");
//					}
					dispose();
					
					
//					System.out.print(atm.setname());
					
//					new Mainwindow(textField.getText());
					//主窗口
					
//					new ATM(textField.getText());
//					new ATM2(textField.getText());
					//取款窗口
					
//					new Save(textField.getText());
					//存钱窗口
					
//					new Query(textField.getText());
					//查询窗口
					
//					new Transfer(textField.getText());
					//转账口
					
//					new Changemima(textField.getText());
					//修改密码窗口
					
				}	
//					System.out.print(textField.getText());
				else if(textField.getText().length()==0 && passwordField.getText().length()!=0) {
					JOptionPane.showMessageDialog(panel_1, "登录失败!\n用户名不可为空!", "错误提示:",JOptionPane.WARNING_MESSAGE);
					}
					else if(textField.getText().length()!=0 && passwordField.getText().length()==0) {
						JOptionPane.showMessageDialog(panel_1, "登录失败!\n密码不可为空!", "错误提示:",JOptionPane.WARNING_MESSAGE);
						}
					
					else if(textField.getText().length()==0 && passwordField.getText().length()==0){
						JOptionPane.showMessageDialog(panel_1, "登录失败!\n用户名和密码不可为空", "错误提示:",JOptionPane.WARNING_MESSAGE);
					}
					
					else {
						textField.setText(null);
						passwordField.setText(null);
						JOptionPane.showMessageDialog(panel_1, "登录失败!\n用户名不存在或者密码不正确!", "错误提示:",JOptionPane.WARNING_MESSAGE);
					}
				}
				catch (Exception e1) {
					
				}

				
			}
		});
		btnNewButton_3_1.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_3_1.setBounds(775, 392, 107, 45);
		contentPane.add(btnNewButton_3_1);

	}


}

ATM账号注册功能:

package test;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileWriter;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.awt.event.ActionEvent;
import java.awt.Toolkit;

public class Enrolled extends JFrame {//注册账号

	public static String name1;
	private JPanel contentPane;
	private JTextField textField;
	private JPasswordField passwordField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Enrolled frame1 = new Enrolled();
					frame1.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Enrolled() {
		setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\JAVA\\My\\\u56FE\u6807\\ConstructionBank.jpg"));
		setTitle("\u6B22\u8FCE\u4F7F\u7528\u94F6\u884CATM\u673A");
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 625, 390);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel_1 = new JLabel("\u8D26\u53F7\uFF1A");
		lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 20));
		lblNewLabel_1.setBounds(109, 83, 78, 44);
		contentPane.add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("\u5BC6\u7801\uFF1A");
		lblNewLabel_2.setFont(new Font("宋体", Font.PLAIN, 20));
		lblNewLabel_2.setBounds(109, 178, 78, 44);
		contentPane.add(lblNewLabel_2);
		
		textField = new JTextField();
		textField.setFont(new Font("宋体", Font.PLAIN, 20));
		textField.setColumns(10);
		textField.setBounds(219, 83, 253, 44);
		contentPane.add(textField);
		
		passwordField = new JPasswordField();
		passwordField.setFont(new Font("宋体", Font.PLAIN, 20));
		passwordField.setEchoChar('*');
		passwordField.setBounds(219, 181, 253, 44);
		contentPane.add(passwordField);
		
		JButton btnNewButton = new JButton("\u53D6\u6D88");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				textField.setText(null);
				passwordField.setText(null);
			}
		});
		btnNewButton.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton.setBounds(109, 274, 106, 53);
		contentPane.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("\u786E\u8BA4");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					DBHelper dbHelper=new DBHelper();
					String sql2 = "select * from atm where binary name ="+"'"+textField.getText()+"'";
					ResultSet rsResultSet = dbHelper.DB(sql2);
					if(rsResultSet.next()==true){//判断该用户名是否存在
						JOptionPane.showMessageDialog(contentPane, "该用户名已存在!", "提示:",JOptionPane.WARNING_MESSAGE);
						dbHelper.downConn();
					}
					else {
							if(textField.getText().matches("[a-zA-Z\\w\\p{Punct}]{5,17}$") 
									&& passwordField.getText().matches("[a-zA-Z\\w\\p{Punct}]{5,17}$")) {//限制账户和密码的长度
								
				            String sql = "insert into atm (balance,name,password) values(?,?,?)"; 
				            PreparedStatement ps = dbHelper.connection.prepareStatement(sql);
				            ps.setString(1, "0");
				            ps.setString(2, textField.getText());//向数据库中添加数据
				            ps.setString(3, passwordField.getText());
				            ps.executeUpdate();
				            
	
				    		String str1=textField.getText()+".txt"; 
				    		File file = new File("D:\\ATM",str1);
				    		file.createNewFile();
				    		
				            JOptionPane.showMessageDialog(contentPane, "注册成功!\n请登录!", "提示:",JOptionPane.WARNING_MESSAGE);
	//			            System.exit(0);
				            dispose ();//关闭当前窗口
							}
							else {
								
								JOptionPane.showMessageDialog(contentPane, "账户名和密码有误!", "错误提示:",JOptionPane.WARNING_MESSAGE);
								JOptionPane.showMessageDialog(contentPane, "账户名和密码由5-17位\n(字母、数字或符号)组成!", "错误提示:",JOptionPane.WARNING_MESSAGE);
							}
					
					}
				
			}
				catch (Exception e1) {	
					
				}
					}
		});
		btnNewButton_1.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_1.setBounds(413, 274, 106, 53);
		contentPane.add(btnNewButton_1);
	}
}

ATM主窗口界面:

package test;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.Font;
import javax.swing.border.TitledBorder;

import com.mysql.cj.x.protobuf.MysqlxPrepare.Execute;

import javax.swing.border.EtchedBorder;
import java.awt.Panel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Toolkit;

public class Mainwindow extends JFrame {
	
	


//	public Mainwindow(String name){
		textField.setText(name);
//		System.out.print(name);
//	}
//	private static String name;
	private JPanel contentPane;
	private JTextField textField;
	public static String name1;
	

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
//					ATMLogin1 atm=new ATMLogin1("");
//					atm.setname();
					Mainwindow frame1 = new Mainwindow(name1);
					frame1.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 * @param name2 
	 */
//	public Mainwindow(String name){
		textField.setText("123");
//		name1=name;
//		System.out.println(name1);
//	}
	public Mainwindow(String name1) {
		setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\JAVA\\My\\\u56FE\u6807\\ConstructionBank.jpg"));
		setResizable(false);
		setTitle("\u6B22\u8FCE\u4F7F\u7528\u94F6\u884CATM\u673A");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 907, 513);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel contentPane_1 = new JPanel();
		contentPane_1.setLayout(null);
		contentPane_1.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane_1.setBackground(Color.WHITE);
		contentPane_1.setBounds(0, 0, 893, 476);
		contentPane.add(contentPane_1);
		
		JButton btnNewButton = new JButton("\u53D6\u6B3E");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ATM frame = new ATM(name1);
				frame.setVisible(true);
				dispose();
			}
		});
		btnNewButton.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton.setBounds(10, 57, 107, 45);
		contentPane_1.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("\u5B58\u6B3E");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Save frame = new Save(name1);
				frame.setVisible(true);
				dispose();
			}
		});
		btnNewButton_1.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_1.setBounds(10, 168, 107, 45);
		contentPane_1.add(btnNewButton_1);
		
		JButton btnNewButton_2 = new JButton("\u8F6C\u8D26");
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Transfer frame = new Transfer(name1);
				frame.setVisible(true);
				dispose();
			}
		});
		btnNewButton_2.setToolTipText("");
		btnNewButton_2.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_2.setBounds(10, 280, 107, 45);
		contentPane_1.add(btnNewButton_2);
		
		JButton btnNewButton_3 = new JButton("");
		btnNewButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		btnNewButton_3.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_3.setBounds(10, 392, 107, 45);
		contentPane_1.add(btnNewButton_3);
		
		JButton btnNewButton_4 = new JButton("\u67E5\u8BE2\u4F59\u989D");
		btnNewButton_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Balance frame = new Balance(name1);
				frame.setVisible(true);
				dispose();
			}
		});
		btnNewButton_4.setFont(new Font("宋体", Font.PLAIN, 17));
		btnNewButton_4.setBounds(775, 57, 107, 45);
		contentPane_1.add(btnNewButton_4);
		
		JButton btnNewButton_1_1 = new JButton("\u4FEE\u6539\u5BC6\u7801");
		btnNewButton_1_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Changemima frame = new Changemima(name1);
				frame.setVisible(true);
				dispose();
			}
		});
		btnNewButton_1_1.setFont(new Font("宋体", Font.PLAIN, 17));
		btnNewButton_1_1.setBounds(775, 168, 107, 45);
		contentPane_1.add(btnNewButton_1_1);
		
		JButton btnNewButton_2_1 = new JButton("\u6570\u636E\u8BB0\u5F55");
		btnNewButton_2_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Query frame = new Query(name1);
				frame.setVisible(true);
				dispose();
			}
		});
		btnNewButton_2_1.setFont(new Font("宋体", Font.PLAIN, 17));
		btnNewButton_2_1.setBounds(775, 280, 107, 45);
		contentPane_1.add(btnNewButton_2_1);
		
		JPanel panel_1 = new JPanel();
		panel_1.setLayout(null);
		panel_1.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(255, 255, 255), new Color(160, 160, 160)), "\u4E3B\u7A97\u53E3", TitledBorder.CENTER, TitledBorder.TOP, new Font("楷体", Font.PLAIN, 35), new Color(255, 0, 0)));
		panel_1.setBackground(Color.WHITE);
		panel_1.setBounds(127, 53, 638, 384);
		contentPane_1.add(panel_1);
		
		JLabel lblNewLabel = new JLabel("\u8BF7\u9009\u62E9\u76F8\u5E94\u529F\u80FD\uFF01");
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 30));
		lblNewLabel.setBounds(214, 141, 274, 93);
		panel_1.add(lblNewLabel);
		
		textField = new JTextField();
		textField.setEditable(false);
		textField.setFont(new Font("宋体", Font.PLAIN, 30));
		textField.setBounds(226, 65, 301, 50);
		panel_1.add(textField);
		textField.setColumns(10);
		textField.setText(name1);
		
		JLabel lblNewLabel_1 = new JLabel("\u8D26\u6237\uFF1A");
		lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 26));
		lblNewLabel_1.setBounds(143, 65, 89, 50);
		panel_1.add(lblNewLabel_1);

		
		
		
		JButton btnNewButton_3_1 = new JButton("\u9000\u51FA");
		btnNewButton_3_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ATMLogin frame = new ATMLogin();
				frame.setVisible(true);
				dispose ();
//				Mainwindow main=new Mainwindow();
//				System.out.print(main.Getname());
				
			}
		});
		btnNewButton_3_1.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_3_1.setBounds(775, 392, 107, 45);
		contentPane_1.add(btnNewButton_3_1);

	}
}


ATM取款功能:

package test;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.Font;
import javax.swing.border.TitledBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.awt.event.ActionEvent;
import java.awt.Toolkit;

public class ATM extends JFrame {//取款

	public static double yuemoney;
	public static String money;
	public static String name1;
	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ATM frame = new ATM(name1);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ATM(String name1) {
		setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\JAVA\\My\\\u56FE\u6807\\ConstructionBank.jpg"));
		setTitle("\u6B22\u8FCE\u4F7F\u7528\u94F6\u884CATM\u673A");
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		setBounds(100, 100, 907, 513);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel contentPane_1 = new JPanel();
		contentPane_1.setLayout(null);
		contentPane_1.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane_1.setBackground(Color.WHITE);
		contentPane_1.setBounds(0, 0, 893, 476);
		contentPane.add(contentPane_1);
		
		JButton btnNewButton = new JButton("1000");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					DBHelper dbHelper=new DBHelper();
					String sql2 = "select * from atm where binary name ="+"'"+name1+"'";
					ResultSet rsResultSet = dbHelper.DB(sql2);
					while (rsResultSet.next()) {
						money=rsResultSet.getString("balance");
						yuemoney=Double.parseDouble(rsResultSet.getString("balance"))-1000;//取款1000
					}
					if(Double.parseDouble(money)>=1000) {
					String sql="update atm set balance=? where name=?"; 
					PreparedStatement ps = dbHelper.connection.prepareStatement(sql);
					ps.setString(1, String.valueOf(yuemoney));
		            ps.setString(2, name1);//修改字段balance数据
					ps.executeUpdate();
					JOptionPane.showMessageDialog(contentPane, "取款成功!", "提示:",JOptionPane.WARNING_MESSAGE);
					}
					else {
						JOptionPane.showMessageDialog(contentPane, "取款失败!\n余额不足!", "提示:",JOptionPane.WARNING_MESSAGE);
					}
				}
					catch(Exception e1) {
						
					}
			}
		});
		btnNewButton.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton.setBounds(10, 57, 107, 45);
		contentPane_1.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("1500");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					DBHelper db=new DBHelper();
					String sql2 = "select * from atm where binary name ="+"'"+name1+"'";
					ResultSet rsResultSet = db.DB(sql2);
					while (rsResultSet.next()) {
						money=rsResultSet.getString("balance");
						yuemoney=Double.parseDouble(rsResultSet.getString("balance"))-1500;//取款1500
					}
					if(Double.parseDouble(money)>=15000) {
					String sql="update atm set balance=? where name=?"; 
					PreparedStatement ps = db.connection.prepareStatement(sql);
					ps.setString(1, String.valueOf(yuemoney));
		            ps.setString(2, name1);//修改字段balance数据
					ps.executeUpdate();
					JOptionPane.showMessageDialog(contentPane, "取款成功!", "提示:",JOptionPane.WARNING_MESSAGE);
					}
					else {
						JOptionPane.showMessageDialog(contentPane, "取款失败!\n余额不足!", "提示:",JOptionPane.WARNING_MESSAGE);
					}
				}
					catch(Exception e1) {
						
					}
			}
		});
		btnNewButton_1.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_1.setBounds(10, 168, 107, 45);
		contentPane_1.add(btnNewButton_1);
		
		JButton btnNewButton_2 = new JButton("2000");
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					DBHelper db=new DBHelper();
					String sql2 = "select * from atm where binary name ="+"'"+name1+"'";
					ResultSet rsResultSet = db.DB(sql2);
					while (rsResultSet.next()) {
						money=rsResultSet.getString("balance");
						yuemoney=Double.parseDouble(rsResultSet.getString("balance"))-2000;//取款2000
					}
					if(Double.parseDouble(money)>=2000) {
					String sql="update atm set balance=? where name=?"; 
					PreparedStatement ps = db.connection.prepareStatement(sql);
					ps.setString(1, String.valueOf(yuemoney));
		            ps.setString(2, name1);//修改字段balance数据
					ps.executeUpdate();
					JOptionPane.showMessageDialog(contentPane, "取款成功!", "提示:",JOptionPane.WARNING_MESSAGE);
					}
					else {
						JOptionPane.showMessageDialog(contentPane, "取款失败!\n余额不足!", "提示:",JOptionPane.WARNING_MESSAGE);
					}
				}
					catch(Exception e1) {
						
					}
			}
		});
		btnNewButton_2.setToolTipText("");
		btnNewButton_2.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_2.setBounds(10, 280, 107, 45);
		contentPane_1.add(btnNewButton_2);
		
		JButton btnNewButton_3 = new JButton("\u5176\u4ED6");
		btnNewButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ATM2 frame = new ATM2(name1);
				frame.setVisible(true);
			}
		});
		btnNewButton_3.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_3.setBounds(10, 392, 107, 45);
		contentPane_1.add(btnNewButton_3);
		
		JButton btnNewButton_4 = new JButton("100");
		btnNewButton_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					DBHelper db=new DBHelper();
					String sql2 = "select * from atm where binary name ="+"'"+name1+"'";
					ResultSet rsResultSet = db.DB(sql2);
					while (rsResultSet.next()) {
						money=rsResultSet.getString("balance");
						yuemoney=Double.parseDouble(rsResultSet.getString("balance"))-100;//取款100
					}
					if(Double.parseDouble(money)>=100) {
					String sql="update atm set balance=? where name=?"; 
					PreparedStatement ps = db.connection.prepareStatement(sql);
					ps.setString(1, String.valueOf(yuemoney));
		            ps.setString(2, name1);//修改字段balance数据
					ps.executeUpdate();
					JOptionPane.showMessageDialog(contentPane, "取款成功!", "提示:",JOptionPane.WARNING_MESSAGE);
					}
					else {
						JOptionPane.showMessageDialog(contentPane, "取款失败!\n余额不足!", "提示:",JOptionPane.WARNING_MESSAGE);
					}
				}
					catch(Exception e1) {
						
					}
			}
		});
		btnNewButton_4.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_4.setBounds(775, 57, 107, 45);
		contentPane_1.add(btnNewButton_4);
		
		JButton btnNewButton_1_1 = new JButton("300");
		btnNewButton_1_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					DBHelper db=new DBHelper();
					String sql2 = "select * from atm where binary name ="+"'"+name1+"'";
					ResultSet rsResultSet = db.DB(sql2);
					while (rsResultSet.next()) {
						money=rsResultSet.getString("balance");
						yuemoney=Double.parseDouble(rsResultSet.getString("balance"))-300;//取款300
					}
					if(Double.parseDouble(money)>=300) {
					String sql="update atm set balance=? where name=?"; 
					PreparedStatement ps = db.connection.prepareStatement(sql);
					ps.setString(1, String.valueOf(yuemoney));
		            ps.setString(2, name1);//修改字段balance数据
					ps.executeUpdate();
					JOptionPane.showMessageDialog(contentPane, "取款成功!", "提示:",JOptionPane.WARNING_MESSAGE);
					}
					else {
						JOptionPane.showMessageDialog(contentPane, "取款失败!\n余额不足!", "提示:",JOptionPane.WARNING_MESSAGE);
					}
				}
					catch(Exception e1) {
						
					}
			}
		});
		btnNewButton_1_1.setFont(new Font("宋体", Font.PLAIN, 17));
		btnNewButton_1_1.setBounds(775, 168, 107, 45);
		contentPane_1.add(btnNewButton_1_1);
		
		JButton btnNewButton_2_1 = new JButton("500");
		btnNewButton_2_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					DBHelper db=new DBHelper();
					String sql2 = "select * from atm where binary name ="+"'"+name1+"'";
					ResultSet rsResultSet = db.DB(sql2);
					while (rsResultSet.next()) {
						money=rsResultSet.getString("balance");
						yuemoney=Double.parseDouble(rsResultSet.getString("balance"))-500;//取款500
					}
					if(Double.parseDouble(money)>=500) {
					String sql="update atm set balance=? where name=?"; 
					PreparedStatement ps = db.connection.prepareStatement(sql);
					ps.setString(1, String.valueOf(yuemoney));
		            ps.setString(2, name1);//修改字段balance数据
					ps.executeUpdate();
					JOptionPane.showMessageDialog(contentPane, "取款成功!", "提示:",JOptionPane.WARNING_MESSAGE);
					}
					else {
						JOptionPane.showMessageDialog(contentPane, "取款失败!\n余额不足!", "提示:",JOptionPane.WARNING_MESSAGE);
					}
				}
					catch(Exception e1) {
						
					}
			}
		});
		btnNewButton_2_1.setFont(new Font("宋体", Font.PLAIN, 17));
		btnNewButton_2_1.setBounds(775, 280, 107, 45);
		contentPane_1.add(btnNewButton_2_1);
		
		JPanel panel_1 = new JPanel();
		panel_1.setLayout(null);
		panel_1.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(255, 255, 255), new Color(160, 160, 160)), "\u73B0\u91D1\u53D6\u6B3E\u7A97\u53E3", TitledBorder.CENTER, TitledBorder.TOP,new Font("宋体", Font.PLAIN, 30), new Color(255, 0, 0)));
		panel_1.setBackground(Color.WHITE);
		panel_1.setBounds(127, 53, 638, 384);
		contentPane_1.add(panel_1);
		
		JLabel lblNewLabel = new JLabel("\u8BF7\u9009\u62E9\u91D1\u989D\uFF01");
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 30));
		lblNewLabel.setBounds(229, 111, 274, 93);
		panel_1.add(lblNewLabel);
		
		JButton btnNewButton_3_1 = new JButton("\u8FD4\u56DE");
		btnNewButton_3_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Mainwindow frame1 = new Mainwindow(name1);
				frame1.setVisible(true);
				dispose();
			}
		});
		btnNewButton_3_1.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_3_1.setBounds(775, 392, 107, 45);
		contentPane_1.add(btnNewButton_3_1);
	}
}


package test;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.awt.event.ActionEvent;
import java.awt.Color;
import java.awt.Label;
import java.awt.Panel;
import javax.swing.SwingConstants;
import java.awt.TextField;
import java.awt.Toolkit;

public class ATM2 extends JFrame {
	
	public static String money;
	public static double yuemoney;
	public static String name1;
	private JPanel contentPane;
	private JTextField textField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ATM2 frame = new ATM2(name1);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ATM2(String name1) {
		setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\JAVA\\My\\\u56FE\u6807\\ConstructionBank.jpg"));
		setTitle("\u6B22\u8FCE\u4F7F\u7528\u94F6\u884CATM\u673A");
		setResizable(false);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 663, 420);
		contentPane = new JPanel();
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		textField = new JTextField();
		textField.setToolTipText("");
		textField.setFont(new Font("宋体", Font.PLAIN, 30));
		textField.setBounds(232, 102, 306, 55);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("\u91D1\u989D\uFF1A");
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 30));
		lblNewLabel.setBounds(112, 102, 110, 55);
		contentPane.add(lblNewLabel);
		
		JButton btnNewButton = new JButton("\u786E\u8BA4");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					DBHelper dbHelper=new DBHelper();
					String sql2 = "select * from atm where binary name ="+"'"+name1+"'";
					ResultSet rsResultSet = dbHelper.DB(sql2);
					while (rsResultSet.next()) {
						money=rsResultSet.getString("balance");
						yuemoney=Double.parseDouble(rsResultSet.getString("balance"))-Double.parseDouble(textField.getText());//取款2000
					}
					if(Double.parseDouble(money)>=Double.parseDouble(textField.getText())) {
					String sql="update atm set balance=? where name=?"; 
					PreparedStatement ps = dbHelper.connection.prepareStatement(sql);
					ps.setString(1, String.valueOf(yuemoney));
		            ps.setString(2, name1);//修改字段balance数据
					ps.executeUpdate();
					JOptionPane.showMessageDialog(contentPane, "取款成功!", "提示:",JOptionPane.WARNING_MESSAGE);
					dispose();
					}
					else {
						JOptionPane.showMessageDialog(contentPane, "取款失败!\n余额不足!", "提示:",JOptionPane.WARNING_MESSAGE);
					}
				}
					catch(Exception e1) {
						
					}
			
				
			}
		});
		btnNewButton.setFont(new Font("宋体", Font.PLAIN, 21));
		btnNewButton.setBounds(127, 273, 97, 55);
		contentPane.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("\u53D6\u6D88");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		btnNewButton_1.setFont(new Font("宋体", Font.PLAIN, 21));
		btnNewButton_1.setBounds(463, 273, 97, 55);
		contentPane.add(btnNewButton_1);
	}
}

ATM存款功能:

package test;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.Font;
import javax.swing.border.TitledBorder;
import javax.swing.border.EtchedBorder;
import java.awt.Panel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.awt.event.ActionListener;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.awt.event.ActionEvent;
import java.awt.Toolkit;

public class Save extends JFrame {//存钱
	
	public static String yue;
	public static String money;
	public static String name1;
	private JPanel contentPane;
	private JTextField textField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Save frame = new Save(name1);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Save(String name1) {
		setResizable(false);
		setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\JAVA\\My\\\u56FE\u6807\\ConstructionBank.jpg"));
		setTitle("\u6B22\u8FCE\u4F7F\u7528\u94F6\u884CATM\u673A");
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		setBounds(100, 100, 907, 513);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel contentPane_1 = new JPanel();
		contentPane_1.setLayout(null);
		contentPane_1.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane_1.setBackground(Color.WHITE);
		contentPane_1.setBounds(0, 0, 893, 476);
		contentPane.add(contentPane_1);
		
		JButton btnNewButton = new JButton("");
		btnNewButton.setBounds(10, 57, 107, 45);
		contentPane_1.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("");
		btnNewButton_1.setBounds(10, 168, 107, 45);
		contentPane_1.add(btnNewButton_1);
		
		JButton btnNewButton_2 = new JButton("");
		btnNewButton_2.setToolTipText("");
		btnNewButton_2.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_2.setBounds(10, 280, 107, 45);
		contentPane_1.add(btnNewButton_2);
		
		JButton btnNewButton_3 = new JButton("\u786E\u8BA4");

		btnNewButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
//				double Addmoney=Double.parseDouble(textField.getText());
				try {
					DBHelper dbHelper=new DBHelper();
					String sql2 = "select * from atm where name ="+"'"+name1+"'";
					ResultSet rsResultSet = dbHelper.DB(sql2);
					while (rsResultSet.next()) {
						yue=rsResultSet.getString("balance");
					}
					if(Double.parseDouble(textField.getText())>=0.01 && textField.getText().matches("[0-9]+")){
					String sql="update atm set balance=? where name=?"; 
					PreparedStatement ps = dbHelper.connection.prepareStatement(sql);
					ps.setString(1,String.valueOf(Double.parseDouble(textField.getText())+Double.parseDouble(yue)));
		            ps.setString(2, name1);//修改字段balance数据
					ps.executeUpdate();
					JOptionPane.showMessageDialog(contentPane, "存款成功!", "提示:",JOptionPane.WARNING_MESSAGE);
					}
					else {
						JOptionPane.showMessageDialog(contentPane, "输入金额错误!\n", "提示:",JOptionPane.WARNING_MESSAGE);
					}
				}
				catch(Exception e1) {
					
				}

			}
		});
		btnNewButton_3.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_3.setBounds(10, 392, 107, 45);
		contentPane_1.add(btnNewButton_3);
		
		JButton btnNewButton_4 = new JButton("");
		btnNewButton_4.setBounds(775, 57, 107, 45);
		contentPane_1.add(btnNewButton_4);
		
		JButton btnNewButton_1_1 = new JButton("");
		btnNewButton_1_1.setBounds(775, 168, 107, 45);
		contentPane_1.add(btnNewButton_1_1);
		
		JButton btnNewButton_2_1 = new JButton("\u66F4\u6B63");
		btnNewButton_2_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				textField.setText(null);
			}
		});
		btnNewButton_2_1.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_2_1.setBounds(775, 280, 107, 45);
		contentPane_1.add(btnNewButton_2_1);
		
		JPanel panel = new JPanel();
		panel.setLayout(null);
		panel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(255, 255, 255), new Color(160, 160, 160)), "\u5B58\u6B3E\u7A97\u53E3", TitledBorder.CENTER, TitledBorder.TOP, new Font("宋体", Font.PLAIN,30), new Color(255, 0, 0)));
		panel.setBackground(Color.WHITE);
		panel.setBounds(127, 35, 638, 392);
		contentPane_1.add(panel);
		
		Panel panel_1 = new Panel();
		panel_1.setLayout(null);
		panel_1.setBackground(Color.WHITE);
		panel_1.setBounds(10, 41, 618, 341);
		panel.add(panel_1);
		
		JLabel lblNewLabel = new JLabel("\u91D1\u989D\uFF1A");
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 25));
		lblNewLabel.setBounds(127, 133, 78, 44);
		panel_1.add(lblNewLabel);
		
		textField = new JTextField();
		textField.setFont(new Font("宋体", Font.PLAIN, 20));
		textField.setColumns(10);
		textField.setBounds(199, 135, 253, 44);
		panel_1.add(textField);
		
		JLabel lblNewLabel_1 = new JLabel("\u8BF7\u8F93\u5165\u5B58\u6B3E\u91D1\u989D\uFF01");
		lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 30));
		lblNewLabel_1.setBounds(184, 32, 272, 57);
		panel_1.add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("\u5143");
		lblNewLabel_2.setFont(new Font("宋体", Font.PLAIN, 25));
		lblNewLabel_2.setBounds(459, 133, 78, 44);
		panel_1.add(lblNewLabel_2);
		
		JButton btnNewButton_3_1 = new JButton("\u8FD4\u56DE");
		btnNewButton_3_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Mainwindow frame1 = new Mainwindow(name1);
				frame1.setVisible(true);
				dispose();
			}
		});
		btnNewButton_3_1.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_3_1.setBounds(775, 392, 107, 45);
		contentPane_1.add(btnNewButton_3_1);
	}

}

ATM转账功能:

package test;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.Font;
import javax.swing.border.TitledBorder;
import javax.swing.border.EtchedBorder;
import java.awt.Panel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.awt.event.ActionListener;
import java.io.FileWriter;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Date;
import java.util.regex.Pattern;
import java.awt.event.ActionEvent;
import java.awt.Toolkit;

public class Transfer extends JFrame {//转账

	public static String money;
	public static double yuemoney;
	public static String money_1;
	public static double yuemoney_1;
	public static String name1;
	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Transfer frame = new Transfer(name1);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Transfer(String name1) {
		setResizable(false);
		setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\JAVA\\My\\\u56FE\u6807\\ConstructionBank.jpg"));
		setTitle("\u6B22\u8FCE\u4F7F\u7528\u94F6\u884CATM\u673A");
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		setBounds(100, 100, 907, 513);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel contentPane_1 = new JPanel();
		contentPane_1.setLayout(null);
		contentPane_1.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane_1.setBackground(Color.WHITE);
		contentPane_1.setBounds(0, 0, 893, 476);
		contentPane.add(contentPane_1);
		
		JButton btnNewButton = new JButton("");
		btnNewButton.setBounds(10, 57, 107, 45);
		contentPane_1.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("");
		btnNewButton_1.setBounds(10, 168, 107, 45);
		contentPane_1.add(btnNewButton_1);
		
		JButton btnNewButton_2 = new JButton("");
		btnNewButton_2.setToolTipText("");
		btnNewButton_2.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_2.setBounds(10, 280, 107, 45);
		contentPane_1.add(btnNewButton_2);
		
		JButton btnNewButton_3 = new JButton("\u786E\u8BA4");
		btnNewButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					DBHelper dbHelper=new DBHelper();
					String sql = "select * from atm where name ="+"'"+textField.getText()+"'";

					ResultSet rsResultSet = dbHelper.DB(sql);


					if(rsResultSet.next()==true && (!textField.getText().equals(name1))){//判断该用户名是否存在
						String sql_2 = "select * from atm where name ="+"'"+textField.getText()+"'";
						ResultSet rsResultSet_1 = dbHelper.DB(sql_2);
						while (rsResultSet_1.next()) {
							money_1=rsResultSet_1.getString("balance");//接收转账账户
						}
						String sql2 = "select * from atm where name ="+"'"+name1+"'";
						ResultSet rsResultSet1 = dbHelper.DB(sql2);
						while (rsResultSet1.next()) {
							money=rsResultSet1.getString("balance");
							yuemoney=Double.parseDouble(money)-Double.parseDouble(textField_1.getText());//转账账户
						}
//							if(Double.parseDouble(textField_1.getText())>=0.01) {
						
							if(Double.parseDouble(textField_1.getText())!=0 && Pattern.matches("^[0-9]+\56{0,1}[0-9]{0,2}$", textField_1.getText())) {
//								System.out.print(textField_1.getText().matches("^[0-9]+\\.{0,1}[0-9]{0,2}$"));
								if(Double.parseDouble(money)>=Double.parseDouble(textField_1.getText()) ) {
								String sql3="update atm set balance=? where name=?"; 
								PreparedStatement ps = dbHelper.connection.prepareStatement(sql3);
								ps.setString(1, String.valueOf(yuemoney));
					            ps.setString(2, name1);//修改字段balance数据
					            
					            String sql_3="update atm set balance=? where name=?";//接收转账账户
					            PreparedStatement ps1 = dbHelper.connection.prepareStatement(sql_3);
								ps1.setString(1, String.valueOf(Double.parseDouble(money_1)+Double.parseDouble(textField_1.getText())));
					            ps1.setString(2, textField.getText());//修改字段balance数据
					            
								ps.executeUpdate();
								ps1.executeUpdate();
								
								String b[]=new String[4];
								String b1[]=new String[4];
								Date nowTime=new Date();
								String a=String.format("%tm月%<td日%<tI时%<tM分",nowTime);
//								System.out.println(a);
								
								b[0]=a; b[1]=textField_1.getText(); b[2]="0"; b[3]=textField.getText();
								b1[0]=a; b1[1]="0"; b1[2]=textField_1.getText(); b1[3]=name1;
								
								//支出账户
								String str1="D:\\ATM\\"+name1+".txt";//把时间、支出金额、对方账户写入支出的账户文件中
								FileWriter file = new FileWriter(str1,true);
								for(int i=0;i<4;i++) {
									file.write(b[i]+"-");
								}
								file.close();
								
								//收入账户
								String str_1="D:\\ATM\\"+textField.getText()+".txt";//把时间、收入金额、对方账户写入收入的账户文件中
								FileWriter file_1 = new FileWriter(str_1,true);
								for(int i=0;i<4;i++) {
									file_1.write(b1[i]+"-");
								}
								file_1.close();
								
								JOptionPane.showMessageDialog(contentPane, "转账成功!", "提示:",JOptionPane.WARNING_MESSAGE);
								}
								else {
									JOptionPane.showMessageDialog(contentPane, "转账失败!\n余额不足!", "提示:",JOptionPane.WARNING_MESSAGE);
								}
							}
							else {
								JOptionPane.showMessageDialog(contentPane, "转账失败!\n输入的金额错误!", "提示:",JOptionPane.WARNING_MESSAGE);
							}
					
				}
					else {
						JOptionPane.showMessageDialog(contentPane, "转账失败!\n账户错误!", "提示:",JOptionPane.WARNING_MESSAGE);
					}
				}
					catch(Exception e1) {
						
					}
			}
		});
		btnNewButton_3.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_3.setBounds(10, 392, 107, 45);
		contentPane_1.add(btnNewButton_3);
		
		JButton btnNewButton_4 = new JButton("");
		btnNewButton_4.setBounds(775, 57, 107, 45);
		contentPane_1.add(btnNewButton_4);
		
		JButton btnNewButton_1_1 = new JButton("");
		btnNewButton_1_1.setBounds(775, 168, 107, 45);
		contentPane_1.add(btnNewButton_1_1);
		
		JButton btnNewButton_2_1 = new JButton("\u66F4\u6B63");
		btnNewButton_2_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				textField.setText(null);
				textField_1.setText(null);
			}
		});
		btnNewButton_2_1.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_2_1.setBounds(775, 280, 107, 45);
		contentPane_1.add(btnNewButton_2_1);
		
		JPanel panel = new JPanel();
		panel.setLayout(null);
		panel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(255, 255, 255), new Color(160, 160, 160)), "\u8F6C\u8D26\u7A97\u53E3", TitledBorder.CENTER, TitledBorder.TOP, new Font("宋体", Font.PLAIN, 30), new Color(255, 0, 0)));
		panel.setBackground(Color.WHITE);
		panel.setBounds(127, 35, 638, 392);
		contentPane_1.add(panel);
		
		Panel panel_1 = new Panel();
		panel_1.setLayout(null);
		panel_1.setBackground(Color.WHITE);
		panel_1.setBounds(10, 41, 618, 341);
		panel.add(panel_1);
		
		JLabel lblNewLabel = new JLabel("\u8D26\u53F7\uFF1A");
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 20));
		lblNewLabel.setBounds(119, 119, 78, 44);
		panel_1.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("\u91D1\u989D\uFF1A");
		lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 20));
		lblNewLabel_1.setBounds(119, 190, 78, 44);
		panel_1.add(lblNewLabel_1);
		
		textField = new JTextField();
		textField.setFont(new Font("宋体", Font.PLAIN, 20));
		textField.setColumns(10);
		textField.setBounds(226, 122, 253, 44);
		panel_1.add(textField);
		
		JLabel lblNewLabel_1_1 = new JLabel("\u8BF7\u8F93\u8981\u8F6C\u5165\u7684\u8D26\u6237\u548C\u91D1\u989D\uFF01");
		lblNewLabel_1_1.setFont(new Font("宋体", Font.PLAIN, 22));
		lblNewLabel_1_1.setBounds(175, 31, 272, 57);
		panel_1.add(lblNewLabel_1_1);
		
		textField_1 = new JTextField();
		textField_1.setFont(new Font("宋体", Font.PLAIN, 20));
		textField_1.setColumns(10);
		textField_1.setBounds(226, 190, 253, 44);
		panel_1.add(textField_1);
		
		JButton btnNewButton_3_1 = new JButton("\u8FD4\u56DE");
		btnNewButton_3_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Mainwindow frame1 = new Mainwindow(name1);
				frame1.setVisible(true);
				dispose();
			}
		});
		btnNewButton_3_1.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_3_1.setBounds(775, 392, 107, 45);
		contentPane_1.add(btnNewButton_3_1);
	}
}

ATM查询余额功能:

package test;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.Font;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.awt.event.ActionEvent;
import java.awt.Color;
import javax.swing.border.TitledBorder;
import javax.swing.border.EtchedBorder;
import java.awt.Panel;
import javax.swing.JPasswordField;
import java.awt.Toolkit;


public class Balance extends JFrame {//查询余额

	public static String yue;
	public static String name1;
	private JPanel contentPane;
	private JPanel contentPane_1;
	private JButton btnNewButton;
	private JButton btnNewButton_1;
	private JButton btnNewButton_2;
	private JButton btnNewButton_3;
	private JButton btnNewButton_4;
	private JButton btnNewButton_1_1;
	private JButton btnNewButton_2_1;
	private JPanel panel;
	private Panel panel_1;
	private JLabel lblNewLabel;
	private JLabel lblNewLabel_1;
	private JTextField textField;
	private JButton btnNewButton_3_1;
	private JTextField textField_1;
//	private String name;
//	ATMLogin1 name=null;
//	private JFrame frame;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {

		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					
					Balance frame = new Balance("");
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Balance(String name1) {
		setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\JAVA\\My\\\u56FE\u6807\\ConstructionBank.jpg"));
		setTitle("\u6B22\u8FCE\u4F7F\u7528\u94F6\u884CATM\u673A");
		setResizable(false);
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		setBounds(100, 100, 907, 513);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		contentPane_1 = new JPanel();
		contentPane_1.setLayout(null);
		contentPane_1.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane_1.setBackground(Color.WHITE);
		contentPane_1.setBounds(0, 0, 893, 476);
		contentPane.add(contentPane_1);
		
		btnNewButton = new JButton("");
		btnNewButton.setBounds(10, 57, 107, 45);
		contentPane_1.add(btnNewButton);
		
		btnNewButton_1 = new JButton("");
		btnNewButton_1.setBounds(10, 168, 107, 45);
		contentPane_1.add(btnNewButton_1);
		
		btnNewButton_2 = new JButton("");
		btnNewButton_2.setToolTipText("");
		btnNewButton_2.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_2.setBounds(10, 280, 107, 45);
		contentPane_1.add(btnNewButton_2);
		
		btnNewButton_3 = new JButton("");
		btnNewButton_3.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_3.setBounds(10, 392, 107, 45);
		contentPane_1.add(btnNewButton_3);
		
		btnNewButton_4 = new JButton("");
		btnNewButton_4.setBounds(775, 57, 107, 45);
		contentPane_1.add(btnNewButton_4);
		
		btnNewButton_1_1 = new JButton("");
		btnNewButton_1_1.setBounds(775, 168, 107, 45);
		contentPane_1.add(btnNewButton_1_1);
		
		btnNewButton_2_1 = new JButton("");
		btnNewButton_2_1.setBounds(775, 280, 107, 45);
		contentPane_1.add(btnNewButton_2_1);
		
		panel = new JPanel();
		panel.setLayout(null);
		panel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(255, 255, 255), new Color(160, 160, 160)), "\u4F59\u989D\u67E5\u8BE2\u7A97\u53E3", TitledBorder.CENTER, TitledBorder.TOP, new Font("宋体", Font.PLAIN, 30), new Color(255, 0, 0)));
		panel.setBackground(Color.WHITE);
		panel.setBounds(127, 35, 638, 392);
		contentPane_1.add(panel);
		
		panel_1 = new Panel();
		panel_1.setLayout(null);
		panel_1.setBackground(Color.WHITE);
		panel_1.setBounds(10, 41, 618, 341);
		panel.add(panel_1);
		
		lblNewLabel = new JLabel("\u8D26\u53F7\uFF1A");
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 20));
		lblNewLabel.setBounds(119, 88, 78, 44);
		panel_1.add(lblNewLabel);
		
		lblNewLabel_1 = new JLabel("\u4F59\u989D\uFF1A");
		lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 20));
		lblNewLabel_1.setBounds(119, 190, 78, 44);
		panel_1.add(lblNewLabel_1);
		
		textField = new JTextField();
		textField.setEditable(false);
		textField.setFont(new Font("宋体", Font.PLAIN, 20));
		textField.setColumns(10);
		textField.setBounds(226, 91, 253, 44);
		textField.setText(name1);
		panel_1.add(textField);
		
		try {
		DBHelper dbHelper = new DBHelper();
		String sql2 = "select * from atm where binary name ="+"'"+name1+"'";
		ResultSet rsResultSet = dbHelper.DB(sql2);
		while (rsResultSet.next()) {
	

			double a=Double.parseDouble(rsResultSet.getString("balance"));
			yue=String.format("%,.2f",a);

//			yue=rsResultSet.getString("balance");
			
			
		}
		}
		catch(Exception e){
			e.printStackTrace();
		}
		
		
		textField_1 = new JTextField();
		textField_1.setEditable(false);
		textField_1.setText(yue+"元");
		textField_1.setFont(new Font("宋体", Font.PLAIN, 20));
		textField_1.setColumns(10);
		textField_1.setBounds(226, 190, 253, 44);
		panel_1.add(textField_1);
		
		btnNewButton_3_1 = new JButton("\u8FD4\u56DE");
		btnNewButton_3_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Mainwindow frame1 = new Mainwindow(name1);
				frame1.setVisible(true);
				dispose();
			}
		});
		btnNewButton_3_1.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_3_1.setBounds(775, 392, 107, 45);
		contentPane_1.add(btnNewButton_3_1);
	}
}

ATM修改密码功能:

package test;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.awt.event.ActionEvent;
import javax.swing.JPasswordField;
import java.awt.Color;
import javax.swing.border.TitledBorder;
import javax.swing.border.EtchedBorder;
import java.awt.Panel;
import java.awt.Toolkit;

public class Changemima extends JFrame {//修改密码

	public static String mima;
	public static String name1;
	private JPanel contentPane;
	private JTextField textField;
	private JPasswordField passwordField;
	private JPasswordField passwordField_1;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Changemima frame = new Changemima(name1);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Changemima(String name1) {
		setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\JAVA\\My\\\u56FE\u6807\\ConstructionBank.jpg"));
		setTitle("\u6B22\u8FCE\u4F7F\u7528\u94F6\u884CATM\u673A");
		setResizable(false);
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		setBounds(100, 100, 907, 513);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel contentPane_1 = new JPanel();
		contentPane_1.setLayout(null);
		contentPane_1.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane_1.setBackground(Color.WHITE);
		contentPane_1.setBounds(0, 0, 893, 476);
		contentPane.add(contentPane_1);
		
		JButton btnNewButton = new JButton("");
		btnNewButton.setBounds(10, 57, 107, 45);
		contentPane_1.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("");
		btnNewButton_1.setBounds(10, 168, 107, 45);
		contentPane_1.add(btnNewButton_1);
		
		JButton btnNewButton_2 = new JButton("");
		btnNewButton_2.setToolTipText("");
		btnNewButton_2.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_2.setBounds(10, 280, 107, 45);
		contentPane_1.add(btnNewButton_2);
		
		JButton btnNewButton_3 = new JButton("\u786E\u8BA4");
		btnNewButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					
					DBHelper dbHelper=new DBHelper();
					String sql2 = "select * from atm where binary name ="+"'"+name1+"'";
					ResultSet rsResultSet = dbHelper.DB(sql2);
					while (rsResultSet.next()) {
						mima=rsResultSet.getString("password");
					}
					
					int queren=JOptionPane.showConfirmDialog(contentPane,"是否确定修改?",  "提示:",JOptionPane.YES_OPTION,JOptionPane.NO_OPTION);
				if(queren==JOptionPane.YES_OPTION) {
					
					if(textField.getText().equals(mima) && (!passwordField.getText().equals(mima)) &&
							passwordField.getText().equals(passwordField_1.getText()) &&
							passwordField.getText().matches("[a-zA-Z\\w\\p{Punct}]{5,17}$") &&
							passwordField_1.getText().matches("[a-zA-Z\\w\\p{Punct}]{5,17}$")) {
						
					String sql = "update atm set password=? where name=?"; //更改password,位置
		            PreparedStatement ps = dbHelper.connection.prepareStatement(sql);
		            ps.setString(1, passwordField.getText());
		            ps.setString(2, name1);
		            ps.executeUpdate();
		            JOptionPane.showMessageDialog(contentPane, "修改成功!\n请重新登录!", "提示:",JOptionPane.WARNING_MESSAGE);
		            
		            dispose();
		            
		            ATMLogin frame = new ATMLogin();
					frame.setVisible(true);
					
					}
					else if((passwordField.getText().length()<5 || passwordField.getText().length()>17 )||
							(passwordField_1.getText().length()<5 || passwordField_1.getText().length()>17)) {
						
						JOptionPane.showMessageDialog(contentPane, "输入的新密码有误!", "错误提示:",JOptionPane.WARNING_MESSAGE);
						JOptionPane.showMessageDialog(contentPane, "密码由5-17位\n(字母、数字或符号)组成!", "错误提示:",JOptionPane.WARNING_MESSAGE);
					
					}
					else if((!textField.getText().equals(mima))) {
						JOptionPane.showMessageDialog(contentPane, "原密码不正确!", "错误提示:",JOptionPane.WARNING_MESSAGE);
					}
					else if( !(passwordField.getText().equals(passwordField_1.getText())) ) {
						JOptionPane.showMessageDialog(contentPane, "两次输入的密码不一致!", "错误提示:",JOptionPane.WARNING_MESSAGE);
					}
					else if( passwordField.getText().equals(textField.getText()) ) {
						JOptionPane.showMessageDialog(contentPane, "新密码不能与原密码相同!", "错误提示:",JOptionPane.WARNING_MESSAGE);
					}
					
					
					dbHelper.downConn();
				}
				else {
					passwordField_1.setText(null);
					passwordField.setText(null);
				}
				}
				catch(Exception e1){
					
				}
			}
		});
		btnNewButton_3.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_3.setBounds(10, 392, 107, 45);
		contentPane_1.add(btnNewButton_3);
		
		JButton btnNewButton_4 = new JButton("");
		btnNewButton_4.setBounds(775, 57, 107, 45);
		contentPane_1.add(btnNewButton_4);
		
		JButton btnNewButton_1_1 = new JButton("");
		btnNewButton_1_1.setBounds(775, 168, 107, 45);
		contentPane_1.add(btnNewButton_1_1);
		
		JButton btnNewButton_2_1 = new JButton("");
		btnNewButton_2_1.setBounds(775, 280, 107, 45);
		contentPane_1.add(btnNewButton_2_1);
		
		JPanel panel = new JPanel();
		panel.setLayout(null);
		panel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(255, 255, 255), new Color(160, 160, 160)), "\u4FEE\u6539\u5BC6\u7801\u7A97\u53E3", TitledBorder.CENTER, TitledBorder.TOP, new Font("宋体", Font.PLAIN, 30), new Color(255, 0, 0)));
		panel.setBackground(Color.WHITE);
		panel.setBounds(127, 35, 638, 392);
		contentPane_1.add(panel);
		
		Panel panel_1 = new Panel();
		panel_1.setLayout(null);
		panel_1.setBackground(Color.WHITE);
		panel_1.setBounds(10, 41, 618, 341);
		panel.add(panel_1);
		
		JLabel lblNewLabel = new JLabel("\u539F\u5BC6\u7801\uFF1A");
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 15));
		lblNewLabel.setBounds(128, 41, 78, 44);
		panel_1.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("\u65B0\u5BC6\u7801\uFF1A");
		lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 15));
		lblNewLabel_1.setBounds(128, 127, 78, 44);
		panel_1.add(lblNewLabel_1);
		
		textField = new JTextField();
		textField.setFont(new Font("宋体", Font.PLAIN, 20));
		textField.setColumns(10);
		textField.setBounds(235, 40, 253, 44);
		panel_1.add(textField);
		
		passwordField = new JPasswordField();
		passwordField.setFont(new Font("宋体", Font.PLAIN, 20));
		passwordField.setEchoChar('*');
		passwordField.setBounds(235, 126, 253, 44);
		panel_1.add(passwordField);
		
		JLabel lblNewLabel_1_1 = new JLabel("\u786E\u8BA4\u5BC6\u7801\uFF1A");
		lblNewLabel_1_1.setFont(new Font("宋体", Font.PLAIN, 15));
		lblNewLabel_1_1.setBounds(128, 216, 78, 44);
		panel_1.add(lblNewLabel_1_1);
		
		passwordField_1 = new JPasswordField();
		passwordField_1.setFont(new Font("宋体", Font.PLAIN, 20));
		passwordField_1.setEchoChar('*');
		passwordField_1.setBounds(235, 215, 253, 44);
		panel_1.add(passwordField_1);
		
		JButton btnNewButton_3_1 = new JButton("\u8FD4\u56DE");
		btnNewButton_3_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Mainwindow frame1 = new Mainwindow(name1);
				frame1.setVisible(true);
				dispose();
			}
		});
		btnNewButton_3_1.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_3_1.setBounds(775, 392, 107, 45);
		contentPane_1.add(btnNewButton_3_1);
	}
}

ATM转账查询功能:

package test;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.Font;
import javax.swing.border.TitledBorder;
import javax.swing.border.EtchedBorder;
import java.awt.Panel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JTable;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.AbstractListModel;
import javax.swing.JScrollBar;
import javax.swing.JTextArea;
import java.awt.List;
import java.awt.Choice;
import java.awt.Scrollbar;
import javax.swing.ScrollPaneConstants;
import java.awt.ScrollPane;
import java.awt.Checkbox;
import javax.swing.ListSelectionModel;
import java.awt.TextArea;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.awt.event.ActionEvent;
import java.awt.Toolkit;

public class Query extends JFrame {//查询

	public static String name1;
	private JPanel contentPane;
	private JTable table;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Query frame = new Query("");
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Query(String name1) {
		setResizable(false);
		setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\JAVA\\My\\\u56FE\u6807\\ConstructionBank.jpg"));
		String[][] value=null;
		setTitle("\u6B22\u8FCE\u4F7F\u7528\u94F6\u884CATM\u673A");
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		setBounds(100, 100, 907, 513);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel contentPane_1 = new JPanel();
		contentPane_1.setLayout(null);
		contentPane_1.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane_1.setBackground(Color.WHITE);
		contentPane_1.setBounds(0, 0, 893, 476);
		contentPane.add(contentPane_1);
		
		JButton btnNewButton = new JButton("");
		btnNewButton.setBounds(10, 57, 107, 45);
		contentPane_1.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("");
		btnNewButton_1.setBounds(10, 168, 107, 45);
		contentPane_1.add(btnNewButton_1);
		
		JButton btnNewButton_2 = new JButton("");
		btnNewButton_2.setToolTipText("");
		btnNewButton_2.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_2.setBounds(10, 280, 107, 45);
		contentPane_1.add(btnNewButton_2);
		
		JButton btnNewButton_3 = new JButton("\u8FD1\u4E00\u4E2A\u6708");
		
		btnNewButton_3.setFont(new Font("宋体", Font.PLAIN, 16));
		btnNewButton_3.setBounds(10, 392, 107, 45);
		contentPane_1.add(btnNewButton_3);
		
		JButton btnNewButton_4 = new JButton("");
		btnNewButton_4.setBounds(775, 57, 107, 45);
		contentPane_1.add(btnNewButton_4);
		
		JButton btnNewButton_1_1 = new JButton("");
		btnNewButton_1_1.setBounds(775, 168, 107, 45);
		contentPane_1.add(btnNewButton_1_1);
		
		JButton btnNewButton_2_1 = new JButton("");
		btnNewButton_2_1.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_2_1.setBounds(775, 280, 107, 45);
		contentPane_1.add(btnNewButton_2_1);
		
		JPanel panel = new JPanel();
		panel.setLayout(null);
		panel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(255, 255, 255), new Color(160, 160, 160)), "\u4EA4\u6613\u8BB0\u5F55\u67E5\u8BE2\u7A97\u53E3", TitledBorder.CENTER, TitledBorder.TOP, new Font("宋体", Font.PLAIN, 30), new Color(255, 0, 0)));
		panel.setBackground(Color.WHITE);
		panel.setBounds(127, 35, 638, 392);
		contentPane_1.add(panel);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 43, 618, 152);
		panel.add(scrollPane);
		
		
		btnNewButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				try {
					String str1="D:\\ATM\\"+name1+".txt";
					BufferedReader br =new BufferedReader(new InputStreamReader(new FileInputStream(str1)));
					String str=null;
					String q=null;
					str = br.readLine();
					String[] msg = str.split("-");
					br.close();
					
					Object name[]= {"日期","支出","收入","对方账号"};//建立表格
					Object a[][];
					a=new Object[msg.length/4][4];//给表格动态赋值
					
					table = new JTable(a,name);
					scrollPane.setViewportView(table);
					int e1=0;
					for(int i=0;i<msg.length/4;i++) {//一维数组转变为二维数组
						if(i>=1) {
							e1=e1+4;
						}
						for(int j=0;j<4;j++) {
							a[i][j]=msg[j+e1];
						}
					}
				}
				 catch (Exception e2) {
					 e2.printStackTrace();
				 }	
				
			}
		});
		
		
		JButton btnNewButton_3_1 = new JButton("\u8FD4\u56DE");
		btnNewButton_3_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Mainwindow frame1 = new Mainwindow(name1);
				frame1.setVisible(true);
				dispose();
			}
		});
		btnNewButton_3_1.setFont(new Font("宋体", Font.PLAIN, 20));
		btnNewButton_3_1.setBounds(775, 392, 107, 45);
		contentPane_1.add(btnNewButton_3_1);
	}
}

在这里插入图片描述
在这里插入图片描述
这以上就是全部的代码和部分功能截图!!!

  • 6
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 13
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

无法识别灬

谢谢您的鼓励!!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值