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

📄 card.java

📁 the function of the system is simulated ATM machine landing, balance inquiries, withdrawals, change
💻 JAVA
字号:
package atm;
//import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
//import java.awt.Dimension;
import java.awt.GridBagLayout;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JButton;
import oo.Sql;
public class Card extends JFrame {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JPanel jPanel = null;

	private JScrollPane jScrollPane = null;

	private JTable jTable = null;

	private JLabel jLabel = null;

	private JComboBox jComboBox = null;

	private JTextField jTextField = null;

	private JButton jButton = null;

	private JButton jButton1 = null;

	private JButton jButton3 = null;

	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
			gridBagConstraints4.gridx = 3;
			gridBagConstraints4.gridy = 1;
			GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
			gridBagConstraints3.gridx = 4;
			gridBagConstraints3.gridy = 1;
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints1.weightx = 1.0;
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints.weightx = 1.0;
			jLabel = new JLabel();
			jLabel.setText("请选择查询条件:");
			jPanel = new JPanel();
			jPanel.setLayout(new GridBagLayout());
			jPanel.add(jLabel, new GridBagConstraints());
			jPanel.add(getJComboBox(), gridBagConstraints);
			jPanel.add(getJTextField(), gridBagConstraints1);
			jPanel.add(getJButton(), new GridBagConstraints());
			jPanel.add(getJButton1(), new GridBagConstraints());
			jPanel.add(getJButton3(), gridBagConstraints3);
			jPanel.add(getJButton4(), gridBagConstraints4);
		}
		return jPanel;
	}

	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setViewportView(getJTable());
		}
		return jScrollPane;
	}

	/**
	 * This method initializes jTable	
	 * 	
	 * @return javax.swing.JTable	
	 */
	private JTable getJTable() {
		if (jTable == null) {
			jTable = new JTable();
		}
		return jTable;
	}

	/**
	 * This method initializes jComboBox	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox() {
		if (jComboBox == null) {
			jComboBox = new JComboBox();
		}
		return jComboBox;
	}

	/**
	 * 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 jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	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()
				select();
				}
			});
		}
		return jButton;
	}

	/**
	 * This method initializes jButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	public void del(){
		Sql dbc = new Sql();
		dbc.getConn();
        int row = jTable.getSelectedRow();
        System.out.println(row);
        if (row < 0) {
            javax.swing.JOptionPane.showMessageDialog(null, "您还没有选中要删除的信息!");
            return;
        }
        Object value = jTable.getValueAt(row, 0);
        String id = value.toString();
        System.out.println(id);
        int returnValue;
	    returnValue = JOptionPane.showConfirmDialog(this, "确实要删除该记录吗?", "确认删除", JOptionPane.YES_NO_OPTION);
	    if (returnValue == JOptionPane.YES_OPTION){

        if (dbc.executeUpdateSQL("DELETE FROM cardInfo WHERE cardID ='" + id+"'")) {
            javax.swing.JOptionPane.showMessageDialog( this,"卡号为" + id + "的顾客信息已成功被删除!请刷新!");
        } else {
            javax.swing.JOptionPane.showMessageDialog(this, "删除失败!请再试。");
        }
	    }else
	    	return ;
	}
	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()
				del();
				}
			});
		}
		return jButton1;
	}

	/**
	 * This method initializes jButton3	
	 * 	
	 * @return javax.swing.JButton	
	 */
	public void close(){
		this.setVisible(false);
	}
	private JButton getJButton3() {
		if (jButton3 == null) {
			jButton3 = new JButton();
			jButton3.setText("关闭");
			jButton3.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
				close();
				}
			});
		}
		return jButton3;
	}

	/**
	 * @param args
	 */
	Connection con=null;
	Sql db=new Sql();

	private JButton jButton4 = null;

	public void showTable(){
		con=db.getConn();
		int count=0;
		ResultSet rs=db.executeQuery("select * from cardInfo");
		try{
			while(rs.next()){
				count++;
			}
			rs.close();
			Object[][] cells=new Object[count][9];
			int i=0;
			rs=db.executeQuery("select * from cardInfo");
			while(rs.next()){
				cells[i]=new Object[]{rs.getString(1),rs.getString(2),
						rs.getString(3),rs.getString(4),
						rs.getString(5),rs.getString(6),
						rs.getString(7),rs.getString(8),rs.getString(9)
				};
				i++;
			}
			String[] colnames={"卡号","货币类型","存款类型","开户日期","开户金额","余额","密码","是否挂失","顾客编号"};
			jTable=new JTable(cells,colnames);
			jScrollPane.setViewportView(jTable);
		}catch(SQLException ex){
			javax.swing.JOptionPane.showMessageDialog(null, ex.getMessage().toString());
		}
	}
	public void select(){
		if(jTextField.getText().equals("")){
			javax.swing.JOptionPane.showMessageDialog(this,"请输入查询信息");
			return ;
		}
		String sql="";
		if(((String)jComboBox.getSelectedItem()).equals("存款类型")){
			sql="select * from cardInfo where savingType='"+jTextField.getText()+"'";
		}else if(((String)jComboBox.getSelectedItem()).equals("顾客姓名")){
			/*sql="select * from userInfo where customerName='"+jTextField.getText()+"'";*/
		}
		if(((String)jComboBox.getSelectedItem()).equals("卡号")){
			sql="select * from cardInfo where cardID='"+jTextField.getText()+"'";
		}else if(((String)jComboBox.getSelectedItem()).equals("顾客姓名")){
			
		}
		if(((String)jComboBox.getSelectedItem()).equals("货币种类")){
			sql="select * from cardInfo where curType='"+jTextField.getText()+"'";
		}else if(((String)jComboBox.getSelectedItem()).equals("顾客姓名")){
			
		}
		if(((String)jComboBox.getSelectedItem()).equals("顾客编号")){
			sql="select * from cardInfo where customerID='"+jTextField.getText()+"'";
		}else if(((String)jComboBox.getSelectedItem()).equals("顾客姓名")){
			
		}
		con=db.getConn();
		int count=0;
		ResultSet rs=db.executeQuery(sql);
		try{
			while(rs.next()){
				count++;
			}
			rs.close();
			Object[][] cells=new Object[count][9];
			int i=0;
			rs=db.executeQuery(sql);
			while(rs.next()){
				cells[i]=new Object[]{rs.getString(1),rs.getString(2),
						rs.getString(3),rs.getString(4),
						rs.getString(5),rs.getString(6),
						rs.getString(7),rs.getString(8),rs.getString(9)
				};
				i++;
			}
			String[] colnames={"卡号","货币类型","存款类型","开户日期","开户金额","余额","密码","是否挂失","顾客编号"};
			jTable=new JTable(cells,colnames);
			jScrollPane.setViewportView(jTable);
		}catch(SQLException ex){
			javax.swing.JOptionPane.showMessageDialog(null, ex.getMessage().toString());
		}
	}
	/**
	 * This method initializes jButton4	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton4() {
		if (jButton4 == null) {
			jButton4 = new JButton();
			jButton4.setText("刷新");
			jButton4.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					initialize1();
				}
			});
		}
		return jButton4;
	}

	/*public static void main(String[] args) {
		// TODO 自动生成方法存根
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				Card thisClass = new Card();
				thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				thisClass.setVisible(true);
			}
		});
	}

	/**
	 * This is the default constructor
	 */	
	public Card() {
		super();

		initialize();
	}
	
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(448, 236);
		this.setContentPane(getJContentPane());
		this.setTitle("卡信息");
		jComboBox.addItem("存款类型");
		jComboBox.addItem("卡号");
		jComboBox.addItem("货币种类");
		jComboBox.addItem("顾客编号");
		this.showTable();
		
	}

	private void initialize1() {
		this.setSize(448, 236);
		this.setContentPane(getJContentPane());
		this.setTitle("卡信息");
		this.showTable();
	}
		/**
	 * 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.NORTH);
			jContentPane.add(getJScrollPane(), BorderLayout.CENTER);
		}
		return jContentPane;
	}
	 public void edit(){
    	 int row = jTable.getSelectedRow();
         if (row < 0) {
             javax.swing.JOptionPane.showMessageDialog(this, "您还未选中任何信息!");
             return;
         }
    //     Object value = jTable.getValueAt(row, 0);
        
       /*  JFrame book=new JFrame();
        
         book.setVisible(true);*/

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

⌨️ 快捷键说明

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