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

📄 usermanage.java

📁 简单的书店管理系统,是课设期间教师指导完成的,希望会对大家有帮助!
💻 JAVA
字号:
package book;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class UserManage extends Mb{
	private MainDAO dao;
	private Table table;
	private JScrollPane scrool;
    private String sql;
    private JLabel name,password,password1;
    private JTextField textname;
    private JPasswordField textpassword,textpassword1;
    private ButtonIcon add,del,save,close;
    private NowEditableModel dtm;
	private ArrayList List = new ArrayList();
	UserManage(String s, int i, int j) throws SQLException{
		super(s, i, j);
		con.setLayout(null);
		dao=new MainDAO();
		
	
		shezhi();
		add();
	}
	
	void shezhi() throws SQLException{
		
		
		name=new JLabel("用户名");
		name.setBounds(20,180,80,18);
		
		password=new JLabel("密码");
		password.setBounds(200,180,80,18);
		
		password1=new JLabel("确认");
		password1.setVisible(false);
		password1.setBounds(200,200,80,18);
		
		textname=new JTextField();
		textname.setBounds(70,180,100,18);
		
		textpassword=new JPasswordField();
		textpassword.setBounds(250,180,100,18);
		
		textpassword1=new JPasswordField();
		textpassword1.setVisible(false);
		textpassword1.setBounds(250,200,100,18);
		
		add=new ButtonIcon("添加");
		add.setBounds(20,230,70,25);
		add.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				add.setEnabled(false);
				save.setEnabled(true);
				del.setEnabled(false);
				table.setEnabled(false);
				password1.setVisible(true);
				textpassword1.setVisible(true);
				textname.setText("");
				textpassword.setText("");
				textpassword1.setText("");
			}
		});
		
		
		del=new ButtonIcon("删除");
		del.setBounds(200,230,70,25);
		del.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
              delJudga();
			}
		});
		
		save=new ButtonIcon("保存");
		save.setBounds(110,230,70,25);
		save.setEnabled(false);
		save.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				MainDAO dao;
				try {
					dao = new MainDAO();
					if(!AddJudge()){
						String str;
						String s="'";
						str="insert into dl values("+s+textname.getText()+s+","+s+textpassword.getText()+s+")";
						dao.insert(str);
						System.out.println(str);
						table.Renovate("select * from dl");	
						
						textname.setText("");
						textpassword.setText("");
						textpassword1.setEnabled(false);
						
						password1.setVisible(false);
						textpassword1.setVisible(false);
						save.setEnabled(false);
						add.setEnabled(true);
						del.setEnabled(true);
						table.setEnabled(true);
					}
				
				} catch (SQLException e1) {
					e1.printStackTrace();
				}
			}
		});
		
		
		//关闭按牛
		close=new ButtonIcon("关闭");
		close.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				close();
			}
		});
		close.setBounds(290,230,70,25);
		
	    dtm=(NowEditableModel)dao.getTableModel("select * from dl");
		table=new Table(dtm);
		table.setPassword();
		scrool=new JScrollPane(table);
		scrool.setBounds(10,10,370,150);
		
		ListSelectionModel rowSM = table.getSelectionModel();
		rowSM.addListSelectionListener(new ListSelectionListener() {
			public void valueChanged(ListSelectionEvent e) {
				if (e.getValueIsAdjusting())
					return;
				ListSelectionModel lsm = (ListSelectionModel) e.getSource();
				if (lsm.isSelectionEmpty()) {
					System.out.println("No rows are selected.");
				} else {
					int selectedRow = lsm.getMinSelectionIndex();
					List = table.getSelectRow(lsm.getMinSelectionIndex(), table.getColumnCount());
					setSelect();
					System.out.println("Row " + selectedRow+ " is now selected.");
				}
			}

		});
		
	}
	
	
	
	
	
	boolean AddJudge(){
		MainDAO dao;
		boolean boo = false;
		try {
			dao = new MainDAO();
			boo=dao.Judge("select 用户名 from dl",textname.getText(),"用户名");
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		if (textname.getText().equals("") || textpassword.getText().equals("")||textpassword1.getText().equals("")) {
			JOptionPane.showMessageDialog(this, "帐号密码不能为空!!!");
		}
		else 
			if(!textpassword.getText().equals(textpassword1.getText())){
				JOptionPane.showMessageDialog(this, "密码不同请重新输入!!!");
				
			}
			else
				if(boo){
					JOptionPane.showMessageDialog(this, "此用户名已存在,请重新输入!!!");
					boo=true;
				}
				else{
					boo=false;
				}
		System.out.println(boo);
		return boo;			
	}
	
	void delJudga(){
		if(textname.getText().equals("") || textpassword.getText().equals("")){
			JOptionPane.showMessageDialog(this, "没选中任何用户!!!!");
		}
		else{
			int n = JOptionPane.showConfirmDialog(this, "确认删除此用户??删除后将不可以恢复!!", "退出",
					JOptionPane.YES_NO_OPTION);
			if (n == 0) {
				MainDAO dao;
				try {
					dao = new MainDAO();
					String str;
						str="delete from dl where 用户名='"+textname.getText()+"'";
						dao.del(str);
						System.out.println(str);
			        	table.Renovate("select * from dl");		
				 } catch (SQLException e1) {
					e1.printStackTrace();
				}
			}
		}
		
	}
	
	//获取选中行的资料
	public void setSelect() {
		textname.setText(List.get(0).toString());
		textpassword.setText(List.get(1).toString());	
	}
	
	void add(){
		con.add(name);con.add(password);con.add(textname);con.add(textpassword);con.add(add);con.add(save);con.add(del);
		con.add(close);con.add(password1);con.add(textpassword1);
		con.add(scrool);
	}
}

⌨️ 快捷键说明

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