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

📄 quanxian.java

📁 线程超市管理系统 采用线程管理的超市管系统
💻 JAVA
字号:
package zh;
import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Quanxian extends JPanel implements ItemListener,ActionListener{
//	JLabel label;
	Connection con=null;
	Statement Stmt=null;
	String [] chs;String s="";
	BoxLayout box;
	JLabel lbemployee_ID,lbemployee_name,
	       lbemployee_password,lbemployee_phone,
	       lbemployee_zhiwei,lbemployee_addr,lbemployee_leibie;
	JTextField txtemployee_ID,txtemployee_name,txtemployee_password,
	           txtemployee_phone,txtemployee_zhiwei,txtemployee_addr,
	           txtemployee_leibie;
    JButton button1,button2,button3,button4,button5;
    JPanel tablePane,buttonsPane,listPane,showPane;
    JPanel pane1,pane2,pane3,pane4;
    List list;
	Quanxian(){
		try {
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		} catch (ClassNotFoundException  ee) {}
//    lbemployee_ID=new JLabel("编号:");
		setBorder(BorderFactory.createTitledBorder("权限管理"));
    lbemployee_name=new JLabel("姓名:");
    lbemployee_password=new JLabel("密码:");
    lbemployee_phone=new JLabel("电话:");
    lbemployee_zhiwei=new JLabel("职位:");
    lbemployee_addr=new JLabel("地址:");
    lbemployee_leibie=new JLabel("职位类别:");
    txtemployee_ID=new JTextField();
    txtemployee_ID.setPreferredSize(new Dimension(150,30));
    txtemployee_ID.setEditable(false);
    txtemployee_name=new JTextField();
    txtemployee_name.setPreferredSize(new Dimension(150,30));
    txtemployee_password=new JTextField();
    txtemployee_password.setPreferredSize(new Dimension(150,30));
    txtemployee_phone=new JTextField();
    txtemployee_phone.setPreferredSize(new Dimension(150,30));
    txtemployee_zhiwei=new JTextField();
    txtemployee_zhiwei.setPreferredSize(new Dimension(150,30));
    txtemployee_addr=new JTextField();
    txtemployee_addr.setPreferredSize(new Dimension(150,30));
    txtemployee_leibie=new JTextField();
    txtemployee_leibie.setPreferredSize(new Dimension(150,30));
    button1=new JButton("添加(A)");
    button1.addActionListener(this);
    button2=new JButton("修改(E)");
    button2.addActionListener(this);
    button3=new JButton("删除(D)");
    button3.addActionListener(this);
    button4=new JButton("取消");
    button4.addActionListener(this);
    button5=new JButton("显示");
    button5.addActionListener(this);
    tablePane=new JPanel();
    buttonsPane=new JPanel();
    listPane=new JPanel();
    showPane=new JPanel();
    GridBagConstraints cons=new GridBagConstraints();
    tablePane.setLayout(new GridBagLayout());
    cons.gridx=0;
    cons.gridy=0;
    cons.gridwidth=1;
    cons.gridheight=1;
    tablePane.add(new JLabel("编号:"),cons);   
    cons.gridx=0;
    cons.gridy=1;
    cons.gridwidth=1;
    cons.gridheight=1;
    tablePane.add(lbemployee_name,cons);
    cons.gridx=2;
    cons.gridy=1;
    cons.gridwidth=1;
    cons.gridheight=1;
    tablePane.add(lbemployee_password,cons);
    cons.gridx=1;
    cons.gridy=0;
    cons.gridwidth=1;
    cons.gridheight=1;
    tablePane.add(txtemployee_ID,cons);
    cons.gridx=1;
    cons.gridy=1;
    cons.gridwidth=1;
    cons.gridheight=1;
    tablePane.add(txtemployee_name,cons);    
    cons.gridx=3;
    cons.gridy=1;
    cons.gridwidth=1;
    cons.gridheight=1;
    tablePane.add(txtemployee_password,cons);
    cons.gridx=0;
    cons.gridy=2;
    cons.gridwidth=1;
    cons.gridheight=1;
    tablePane.add(lbemployee_phone,cons);   
    cons.gridx=2;
    cons.gridy=2;
    cons.gridwidth=1;
    cons.gridheight=1;
    tablePane.add(lbemployee_zhiwei,cons);
    cons.gridx=0;
    cons.gridy=3;
    cons.gridwidth=1;
    cons.gridheight=1;
    tablePane.add(lbemployee_addr,cons);
    cons.gridx=1;
    cons.gridy=2;
    cons.gridwidth=1;
    cons.gridheight=1;
    tablePane.add(txtemployee_phone,cons);
    cons.gridx=3;
    cons.gridy=2;
    cons.gridwidth=1;
    cons.gridheight=1;
    tablePane.add(txtemployee_zhiwei,cons);   
    cons.gridx=1;
    cons.gridy=3;
    cons.gridwidth=1;
    cons.gridheight=1;
    tablePane.add(txtemployee_addr,cons);
    cons.gridx=2;
    cons.gridy=3;
    cons.gridwidth=1;
    cons.gridheight=1;
    tablePane.add(lbemployee_leibie,cons);
    cons.gridx=3;
    cons.gridy=3;
    cons.gridwidth=1;
    cons.gridheight=1;
    tablePane.add(txtemployee_leibie,cons);

    buttonsPane.setLayout(new GridLayout(1,4));
    buttonsPane.add(button1);
    buttonsPane.add(button2);
    buttonsPane.add(button3);
    buttonsPane.add(button4);
    showPane.setLayout(new BorderLayout());
    showPane.add(buttonsPane,BorderLayout.SOUTH);
    showPane.add(tablePane,BorderLayout.CENTER);
    listPane.setLayout(new BorderLayout());
    listPane.add(new JLabel("系统用户列表"),BorderLayout.NORTH);
    listPane.add(button5,BorderLayout.SOUTH);
    list=new List(7,false);
    listPane.add(list,BorderLayout.CENTER);
    
    setLayout(new BorderLayout());
    add(showPane,BorderLayout.EAST);
	add(listPane,BorderLayout.WEST);
    
    list.addItemListener(this);
  }
	public void actionPerformed (ActionEvent e){
		if(e.getSource()==button5){
		ResultSet rs;		
		String name2;

		try {
		
			con = DriverManager.getConnection("jdbc:odbc:zz",
					"", "");
			 Stmt = con.createStatement();
			rs = Stmt.executeQuery("select * from password");

		while (rs.next()) {
					name2 = rs.getString(2);
					list.add(name2.toString());
					
					}
			         
			        
					
			

			con.close();

		} catch (java.lang.Exception ee) {}
	}
		else if(e.getSource()==button1){
			try {

				 con = DriverManager.getConnection("jdbc:odbc:zz",
						"", "");
				 Stmt = con.createStatement();

				String s2="'"+txtemployee_name.getText().trim()+"'";
				String s3="'"+txtemployee_password.getText().trim()+"'";
				String s4="'"+txtemployee_phone.getText().trim()+"'";
				String s5="'"+txtemployee_zhiwei.getText().trim()+"'";
				String s6="'"+txtemployee_addr.getText().trim()+"'";
				String s7="'"+txtemployee_leibie.getText().trim()+"'";
				String temp="INSERT  INTO password (name,password,phone,zhiwei,addr,leibie) VALUES("+s2+","+s3+","+s4+","+s5+","+s6+","+s7+")";
				System.out.print("55555");
				Stmt.executeUpdate(temp);
				con.close();
				
			} catch (java.lang.Exception ee) {}
		}
		else if(e.getSource()==button2){
			try {

				 con = DriverManager.getConnection("jdbc:odbc:zz",
						"", "");
				 Stmt = con.createStatement();
				 int s1=Integer.parseInt(txtemployee_ID.getText().trim());
					String s2="'"+txtemployee_name.getText().trim()+"'";
					String s3="'"+txtemployee_password.getText().trim()+"'";
					String s4="'"+txtemployee_phone.getText().trim()+"'";
					String s5="'"+txtemployee_zhiwei.getText().trim()+"'";
					String s6="'"+txtemployee_addr.getText().trim()+"'";
					String s7="'"+txtemployee_leibie.getText().trim()+"'";
					String tmp1="UPDATE password set name="+s2+"where ID="+s1;
					String tmp2="UPDATE password set password="+s3+"where ID="+s1;
					String tmp3="UPDATE password set phone="+s4+"where ID="+s1;
					String tmp4="UPDATE password set zhiwei="+s5+"where ID="+s1;
					String tmp5="UPDATE password set addr="+s6+"where ID="+s1;
					String tmp6="UPDATE password set leibie="+s7+"where ID="+s1;
					Stmt.executeUpdate(tmp1);
					Stmt.executeUpdate(tmp2);
					Stmt.executeUpdate(tmp3);
					Stmt.executeUpdate(tmp4);
					Stmt.executeUpdate(tmp5);
					Stmt.executeUpdate(tmp6);
					con.close();
			}catch(java.lang.Exception ee){}
		}
		else if(e.getSource()==button3){
			try {

				 con = DriverManager.getConnection("jdbc:odbc:zz",
						"", "");
				 Stmt = con.createStatement();
				 int syh=Integer.parseInt(txtemployee_ID.getText());
				 Stmt.executeUpdate("delete from password where ID="+syh );
				 con.close();
			}catch(java.lang.Exception ee){}
		}
		else if (e.getSource() == button4) {
			txtemployee_ID.setText(null);
			txtemployee_name.setText(null);
			txtemployee_password.setText(null);
			txtemployee_phone.setText(null);
			txtemployee_zhiwei.setText(null);
			txtemployee_addr.setText(null);
			txtemployee_leibie.setText(null);
		}
}
	
	public void itemStateChanged(ItemEvent e)
    {
		if(e.getItemSelectable()==list)
        {
			chs= list.getSelectedItems( );
			for ( int i =0; i<chs.length; i++)
            { s=chs[i];}
			ResultSet rs;

			String name1,name7,name2, name3, name4, name5, name6;
			String syh = "'"+s.trim()+"'";
			try {

				con = DriverManager.getConnection("jdbc:odbc:zz",
						"", "");
				 Stmt = con.createStatement();
				rs = Stmt.executeQuery("select * from password where name=" + syh);

				while (rs.next()) {
					

					    name1=rs.getString(1);
						name2 = rs.getString(2);
						name3 = rs.getString(3);
						name4 = rs.getString(4);
						name5 = rs.getString(5);
						name6 = rs.getString(6);
						name7 = rs.getString(7);
						txtemployee_ID.setText(name1);
						txtemployee_name.setText(name2);
						txtemployee_password.setText(name3);
						txtemployee_phone.setText(name4);
						txtemployee_zhiwei.setText(name5);
						txtemployee_addr.setText(name6);
						txtemployee_leibie.setText(name7);

					
				}

				con.close();


			} catch (java.lang.Exception ee) {}
        }
    }
	
}

⌨️ 快捷键说明

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