⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userfrm.java

📁 ATM系统分为前台和后台
💻 JAVA
字号:
package atm;

import javax.swing.SwingUtilities;
import oo.Sql;
import java.sql.*;
import javax.swing.JOptionPane;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;

import javax.swing.ButtonGroup;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.JComboBox;
//import java.awt.Dimension;
//import javax.swing.JOptionPane;
import java.awt.event.KeyEvent;
import javax.swing.JRadioButton;

public class UserFrm extends JFrame {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JPanel jPanel = null;

	private JLabel jLabel = null;

	private JTextField jTextField = null;

	private JLabel jLabel1 = null;

	private JPasswordField jPasswordField = null;

	private JButton jButton = null;

	private JButton jButton1 = null;
	public static String cardID;


	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			GridBagConstraints gridBagConstraints12 = new GridBagConstraints();
			gridBagConstraints12.gridx = 1;
			gridBagConstraints12.gridy = 4;
			GridBagConstraints gridBagConstraints21 = new GridBagConstraints();
			gridBagConstraints21.gridx = 0;
			gridBagConstraints21.gridy = 3;
			jLabel3 = new JLabel();
			jLabel3.setText("用户密码:");
			GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
			gridBagConstraints11.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints11.gridy = 3;
			gridBagConstraints11.weightx = 1.0;
			gridBagConstraints11.gridx = 1;
			GridBagConstraints gridBagConstraints10 = new GridBagConstraints();
			gridBagConstraints10.gridx = 2;
			gridBagConstraints10.gridy = 3;
			GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
			gridBagConstraints9.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints9.gridy = 2;
			gridBagConstraints9.weightx = 1.0;
			gridBagConstraints9.gridx = 1;
			GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
			gridBagConstraints8.gridx = 0;
			gridBagConstraints8.gridy = 2;
			jLabel2 = new JLabel();
			jLabel2.setText("用户卡号:");
			jLabel2.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED);
			GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
			gridBagConstraints5.gridx = 2;
			gridBagConstraints5.gridy = 4;
			GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
			gridBagConstraints4.gridx = 2;
			gridBagConstraints4.gridy = 1;
			GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
			gridBagConstraints3.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints3.gridy = 1;
			gridBagConstraints3.weightx = 1.0;
			gridBagConstraints3.gridx = 1;
			GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
			gridBagConstraints2.gridx = 0;
			gridBagConstraints2.gridy = 1;
			jLabel1 = new JLabel();
			jLabel1.setText("管理员密码:");
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints1.gridy = 0;
			gridBagConstraints1.weightx = 1.0;
			gridBagConstraints1.gridx = 1;
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.gridx = 0;
			gridBagConstraints.gridy = 0;
			jLabel = new JLabel();
			jLabel.setText("管理员姓名:");
			jPanel = new JPanel();
			jPanel.setLayout(new GridBagLayout());
			jPanel.add(jLabel, gridBagConstraints);
			jPanel.add(getJTextField(), gridBagConstraints1);
			jPanel.add(jLabel1, gridBagConstraints2);
			jPanel.add(getJPasswordField(), gridBagConstraints3);
			jPanel.add(getJButton(), gridBagConstraints4);
			jPanel.add(getJButton1(), gridBagConstraints5);
			jPanel.add(jLabel2, gridBagConstraints8);
			jPanel.add(getJComboBox(), gridBagConstraints9);
			jPanel.add(getJButton2(), gridBagConstraints10);
			jPanel.add(getJPasswordField1(), gridBagConstraints11);
			jPanel.add(jLabel3, gridBagConstraints21);
			jPanel.add(getJPanel1(), gridBagConstraints12);
		}
		return jPanel;
	}

	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField() {
		if (jTextField == null) {
			jTextField = new JTextField();
			jTextField.setColumns(8);
		}
		return jTextField;
	}

	/**
	 * This method initializes jPasswordField	
	 * 	
	 * @return javax.swing.JPasswordField	
	 */
	private JPasswordField getJPasswordField() {
		if (jPasswordField == null) {
			jPasswordField = new JPasswordField();
			jPasswordField.setColumns(8);
		}
		return jPasswordField;
	}

	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	Sql db=new Sql();  //  @jve:decl-index=0:
	public static String user;
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setText("登录");
			jButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					if(jTextField.getText().equals("")||jPasswordField.getPassword().equals("")&&jPasswordField1.getPassword().equals("")){
						JOptionPane.showMessageDialog(null, "请先选择登陆角色!");
			
					}else{
						Connection con;
						con=db.getConn();
						user=String.valueOf(jTextField.getText());
						String pass=String.valueOf(jPasswordField.getPassword());
						boolean bb=db.isValid(con, user, pass);
						if(bb){
								if(jTextField.getText().equals("admin")||jTextField.getText().equals("admin1")||jTextField.getText().equals("admin2")){
									MFrm m=new MFrm();
									m.setVisible(true);
									close();
								}else{
									if(i==0)  
										JOptionPane.showMessageDialog(null, "密码输错3次!请到柜台改密码!");
									else {
										i--;
										JOptionPane.showMessageDialog(null, "密码错误!请重新输入!!");
									}
								}
						}else{
							JOptionPane.showMessageDialog(null, "该管理员不存在!");
						}
					}
				}
			});
		}
		return jButton;
	}
	public void close(){
		this.setVisible(false);
	}
	/**
	 * This method initializes jButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton1() {
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setText("退出");
			jButton1.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
				System.exit(-1);
				}
			});
		}
		return jButton1;
	}

	/**
	 * @param args
	 */
	static UserFrm thisClass;

	private JLabel jLabel2 = null;

	private JComboBox jComboBox = null;

	private JButton jButton2 = null;
	public int i=3; 
	private Connection con=null;
	/**
	 * This method initializes jComboBox	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox() {
		if (jComboBox == null) {
			jComboBox = new JComboBox();
		}
		return jComboBox;
	}

	/**
	 * This method initializes jButton2	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton2() {
		if (jButton2 == null) {
			jButton2 = new JButton();
			jButton2.setText("登录");
			jButton2.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					if(jPasswordField1.getPassword().equals("")){
						JOptionPane.showMessageDialog(null, "请先选择登陆角色!");
					}else{
						con=db.getConn();
						cardID=String.valueOf(jComboBox.getSelectedItem());
						String pass=String.valueOf(jPasswordField1.getPassword());
						boolean bb=db.isValid1(con, cardID, pass);
						if(bb){
							UMFrm ym=new UMFrm();
							ym.setVisible(true);
							close();
						}else{
							if(i==0)  
								JOptionPane.showMessageDialog(null, "密码输错3次!请到柜台改密码!");
							else {
								i--;
								JOptionPane.showMessageDialog(null, "密码错误!请重新输入!!");
							}
						}
					}
					}
				});
		}
		return jButton2;
	}
	
//	public static String cardID;

	private JPasswordField jPasswordField1 = null;

	private JLabel jLabel3 = null;

	private JPanel jPanel1 = null;

	private JRadioButton jRadioButton = null;

	private JRadioButton jRadioButton1 = null;
	
	private ButtonGroup group;  //  @jve:decl-index=0:
	/**
	 * This method initializes jPasswordField1	
	 * 	
	 * @return javax.swing.JPasswordField	
	 */
	private JPasswordField getJPasswordField1() {
		if (jPasswordField1 == null) {
			jPasswordField1 = new JPasswordField();
			jPasswordField1.setColumns(8);
		}
		return jPasswordField1;
	}

	/**
	 * This method initializes jPanel1	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
			gridBagConstraints6.gridx = -1;
			gridBagConstraints6.gridy = -1;
			jPanel1 = new JPanel();
			jPanel1.setLayout(new GridBagLayout());
			jPanel1.add(getJRadioButton(), gridBagConstraints6);
			jPanel1.add(getJRadioButton1(), new GridBagConstraints());
			group=new ButtonGroup();///
			group.add(getJRadioButton1());
			group.add(getJRadioButton());
		}
		return jPanel1;
	}

	/**
	 * This method initializes jRadioButton	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getJRadioButton() {
		if (jRadioButton == null) {
			jRadioButton = new JRadioButton();
			jRadioButton.setText("用户");
			jRadioButton.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					System.out.println("itemStateChanged()"); // TODO Auto-generated Event stub itemStateChanged()
					if(jRadioButton.isSelected()){
						f=1;
						n=0;
					jTextField.setEnabled(false);
					jPasswordField.setEnabled(false);
						jButton.setEnabled(false);
					}else{
						jTextField.setEnabled(true);
						jPasswordField.setEnabled(true);
							jButton.setEnabled(true);
					}
				}
			});
		}
		return jRadioButton;
	}
	/**
	 * This method initializes jRadioButton1	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getJRadioButton1() {
		if (jRadioButton1 == null) {
			jRadioButton1 = new JRadioButton();
			jRadioButton1.setText("管理员");
			jRadioButton1.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					System.out.println("itemStateChanged()"); // TODO Auto-generated Event stub itemStateChanged()
					if(jRadioButton1.isSelected()){
						f=0;
						n=1;
						jComboBox.setEnabled(false);
						jPasswordField1.setEnabled(false);
						jButton2.setEnabled(false);
					}else{
						jComboBox.setEnabled(true);
						jPasswordField1.setEnabled(true);
						jButton2.setEnabled(true);
					}
				}
			});
		}
		return jRadioButton1;
	}
	int f=1,n=1;
	public static void main(String[] args) {
		// TODO 自动生成方法存根
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				thisClass = new UserFrm();
				thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				thisClass.setVisible(true);
			}
		});
	}

	/**
	 * This is the default constructor
	 */
	public UserFrm() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(376, 227);
		this.setContentPane(getJContentPane());
		this.setTitle("登录窗");
		
		try{
			con=db.getConn();
			ResultSet rs=db.executeQuery("select * from cardInfo");
			while(rs.next()){
				jComboBox.addItem(rs.getString(1));
			}
		}catch(Exception E){
			E.printStackTrace();
		}finally{
			db.closeDB();
		}
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(getJPanel(), BorderLayout.CENTER);
		}
		return jContentPane;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -