tjgly.java

来自「基于Java——SQL2005 的java课程设计 仓库管理系统。主要功能」· Java 代码 · 共 282 行

JAVA
282
字号
package windows;

import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import Login.Item;
import Login.Login;
import sql.sql;
import model.TbUserlist;

public class TJGLY extends JInternalFrame {
	private JTextField logName;
	private JPasswordField passwordField_1;
	private JPasswordField passwordField;
	private JTextField name;
	String msg="";
	int type=JOptionPane.PLAIN_MESSAGE;
	private TbUserlist user = Login.getUser();
	private void clear() {
		logName.setText(null);
		name.setText(null);
		passwordField_1.setText(null);
		passwordField.setText(null);
		name.requestFocus();
	}
	public TJGLY() {
		super();
		if(user.getQuan().equals("超级管理员")){
		setClosable(true);
		setIconifiable(true);
		setLayout(new GridBagLayout());
		setBounds(270, 100, 280, 236);
		setTitle("管理员管理之添加管理员");
	
		final JLabel label = new JLabel();
		label.setFont(new Font("", Font.PLAIN, 14));
		label.setText("管理员姓名:");
		final GridBagConstraints gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridy = 0;
		gridBagConstraints.gridx = 0;
		add(label, gridBagConstraints);
		
		name = new JTextField();
		name.setFont(new Font("", Font.PLAIN, 14));
		final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints();
		gridBagConstraints_1.weightx = 1.0;
		gridBagConstraints_1.weighty = 1.0;
		gridBagConstraints_1.ipadx = -250;
		gridBagConstraints_1.insets = new Insets(0, 0, 0, 10);
		gridBagConstraints_1.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints_1.gridwidth = 2;
		gridBagConstraints_1.gridy = 0;
		gridBagConstraints_1.gridx = 1;
		add(name, gridBagConstraints_1);
		/*
     public int anchor         对齐方式。
     public int fill           描述当容器变形时,控制组件是否增长。
     public gridheight         描述了组件所占网格的个数,gridheight描述在纵向上所占网格的个数
     Public gridweight         描述在横向上所占网格的个数。
     public girdx              描述组件在布局时应处于那个网格位置,即描述网格x轴开始的位置。
     public gridy              同样是网格开始的位置,gridy为y轴上开始的位置。
     public Insets insets      用来调整它周围的空间大小。
     public int ipadx          组件最小尺寸的约束条件。
     public int ipady          组件最小尺寸的约束条件。
     public double weightx     描述当容器变形时,单元格本身在x轴上(横向上)如何缩放。
     public double weighty     描述当容器变形时,单元格本身在y轴上(纵向上)如何缩放。
		 * */
		final JLabel label_4 = new JLabel();
		label_4.setFont(new Font("", Font.PLAIN, 14));
		label_4.setText("用户名:");
		final GridBagConstraints gridBagConstraints_10 = new GridBagConstraints();
		gridBagConstraints_10.gridy = 1;
		gridBagConstraints_10.gridx = 0;
		add(label_4, gridBagConstraints_10);
		
		logName = new JTextField();
		final GridBagConstraints gridBagConstraints_11 = new GridBagConstraints();
		gridBagConstraints_11.weighty = 1.0;
		gridBagConstraints_11.insets = new Insets(0, 0, 0, 10);
		gridBagConstraints_11.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints_11.gridwidth = 2;
		gridBagConstraints_11.gridy = 1;
		gridBagConstraints_11.gridx = 1;
		add(logName, gridBagConstraints_11);
		
		final JLabel label_2 = new JLabel();
		label_2.setFont(new Font("", Font.PLAIN, 14));
		label_2.setText("输入密码:");
		final GridBagConstraints gridBagConstraints_4 = new GridBagConstraints();
		gridBagConstraints_4.gridy = 2;
		gridBagConstraints_4.gridx = 0;
		add(label_2, gridBagConstraints_4);
		
		passwordField = new JPasswordField();
		final GridBagConstraints gridBagConstraints_5 = new GridBagConstraints();
		gridBagConstraints_5.weighty = 1.0;
		gridBagConstraints_5.insets = new Insets(0, 0, 0, 10);
		gridBagConstraints_5.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints_5.gridwidth = 2;
		gridBagConstraints_5.gridy = 2;
		gridBagConstraints_5.gridx = 1;
		add(passwordField, gridBagConstraints_5);
		
		final JLabel label_3 = new JLabel();
		label_3.setFont(new Font("", Font.PLAIN, 14));
		label_3.setText("确认密码:");
		final GridBagConstraints gridBagConstraints_6 = new GridBagConstraints();
		gridBagConstraints_6.gridy = 3;
		gridBagConstraints_6.gridx = 0;
		add(label_3, gridBagConstraints_6);
		
		passwordField_1 = new JPasswordField();
		final GridBagConstraints gridBagConstraints_7 = new GridBagConstraints();
		gridBagConstraints_7.weighty = 1.0;
		gridBagConstraints_7.insets = new Insets(0, 0, 0, 10);
		gridBagConstraints_7.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints_7.gridwidth = 2;
		gridBagConstraints_7.gridy = 3;
		gridBagConstraints_7.gridx = 1;
		add(passwordField_1, gridBagConstraints_7);
		
		final JButton button = new JButton();
		button.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				//String tbName = logName.getText();
				//String tbUsername = name.getText();
				
				String sqlyuju = "select * from tb_userlist where ";
				List GLYInfo = sql.findForList(sqlyuju + "name='" + name.getText().trim() +"'");
				List<Item> items = new ArrayList<Item>();
				Iterator iter = GLYInfo.iterator();
				List GLYInfo1 = sql.findForList(sqlyuju + "username='" + logName.getText() + "'");
				List<Item> items1 = new ArrayList<Item>();
				Iterator iter1 = GLYInfo1.iterator();
				
				if(iter.hasNext()||iter1.hasNext())
				{					
					//type=JOptionPane.ERROR_MESSAGE;
					//msg="此管理员名称已经存在";
					//JOptionPane.showConfirmDialog(TJGLY.this, msg, "E时代仓库信息管理系统添加管理员提示", opttype,type);	
					//JOptionPane.showConfirmDialog(parentComponent, message, sqlyuju, optionType, messageType, icon)
 
					JOptionPane   j   =   new   JOptionPane("此管理员名称或者用户名已经存在,是否重新添加管理员?",   JOptionPane.QUESTION_MESSAGE,JOptionPane.YES_NO_OPTION,null,new   Object[]{"  是  ","  否  "});   
					Object[]   xx   =   j.getOptions();   
					int i=JOptionPane.showOptionDialog(TJGLY.this,"此管理员名称或者用户名已经存在,是否重新添加管理?","E时代仓库信息管理系统添加管理员提示",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,xx,"  是  ");  
					if(i==0)
						clear();
					else
					dispose();				
				}
				
				//String password = new String(passwordField.getPassword());
				/*TbUserlist user = sql.getUser(tbName, password);
				if (user.getUsername() != null && !user.getUsername().isEmpty()) {
					JOptionPane.showMessageDialog(TJGLY.this,
							"此登录名称已经存在");
					name.setFocusable(true);
					return;
				}*/
				else{ if (name.getText() == null || name.getText().equals("")||logName.getText()==null ||logName.getText().equals("")) {
					type=JOptionPane.ERROR_MESSAGE;
					msg="管理员姓名或者用户名不能为空";
					JOptionPane.showMessageDialog(TJGLY.this, msg, "E时代仓库信息管理系统添加管理员提示",type);
					//JOptionPane.showMessageDialog(TJGLY.this, "用户名不能为空");
					clear();
					//name.setRequestFocusEnabled(true);
					return;
				}
				if (passwordField.getPassword().length == 0) {
					type=JOptionPane.ERROR_MESSAGE;
					msg="密码不能为空";
					JOptionPane.showMessageDialog(TJGLY.this, msg, "E时代仓库信息管理系统添加管理员提示",type);	
					passwordField_1.setText(null);
					passwordField.requestFocus();
					//JOptionPane.showMessageDialog(TJGLY.this, "密码不能为空");
				} else if (passwordField.getText().equals(
						passwordField_1.getText())) {
					TbUserlist tbUserlist = new TbUserlist();
					tbUserlist.setQuan("管理员");
					tbUserlist.setPass(passwordField_1.getText());
					tbUserlist.setName(logName.getText().trim());
					tbUserlist.setUsername(name.getText().trim());
					sql.addUser(tbUserlist);
					
					JOptionPane   j   =   new   JOptionPane("管理员添加成功,是否继续添加管理员?",   JOptionPane.QUESTION_MESSAGE,JOptionPane.YES_NO_OPTION,null,new   Object[]{"   是   ","   否   "});   
					Object[]   xx   =   j.getOptions();   
					int i=JOptionPane.showOptionDialog(TJGLY.this,"管理员添加成功,是否继续添加管理员?","E时代仓库信息管理系统添加管理员提示",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,xx,"   否   ");  
					if(i==0)
						clear();
					else
					dispose();		
					//JOptionPane.showMessageDialog(TJGLY.this, "操作员添加成功");
					//clear();
				} else {
					type=JOptionPane.ERROR_MESSAGE;
					msg="两次密码输入不相同";
					JOptionPane.showMessageDialog(TJGLY.this, msg, "E时代仓库信息管理系统添加管理员提示",type);	
					passwordField_1.setText(null);
					passwordField.setText(null);
					passwordField.requestFocus();
					//JOptionPane.showMessageDialog(TJGLY.this, "两次密码输入不相同");
				}
			}
			}
		});
		button.setText("添加");
		final GridBagConstraints gridBagConstraints_8 = new GridBagConstraints();
		gridBagConstraints_8.weighty = 1.0;
		gridBagConstraints_8.anchor = GridBagConstraints.EAST;
		gridBagConstraints_8.gridy = 5;
		gridBagConstraints_8.gridx = 1;
		add(button, gridBagConstraints_8);

		final JButton button_1 = new JButton();
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				clear();
			}
		});
		button_1.setText("重写");
		final GridBagConstraints gridBagConstraints_9 = new GridBagConstraints();
		gridBagConstraints_9.weighty = 1.0;
		gridBagConstraints_9.gridy = 5;
		gridBagConstraints_9.gridx = 2;
		add(button_1, gridBagConstraints_9);
		
		name.addKeyListener(new KeyAdapter() {
			public void keyPressed(final KeyEvent e) {
				if (e.getKeyCode() == KeyEvent.VK_ENTER)
					logName.requestFocus();
			}
		});//侦听键盘事件,输完密码后回车就激活登录按钮
		
		logName.addKeyListener(new KeyAdapter() {
			public void keyPressed(final KeyEvent e) {
				if (e.getKeyCode() == KeyEvent.VK_ENTER)
					passwordField.requestFocus();
			}
		});//侦听键盘事件,输完密码后回车就激活登录按钮
		
		passwordField.addKeyListener(new KeyAdapter() {
			public void keyPressed(final KeyEvent e) {
				if (e.getKeyCode() == KeyEvent.VK_ENTER)
					passwordField_1.requestFocus();
			}
		});//侦听键盘事件,输完密码后回车就激活登录按钮
		
		passwordField_1.addKeyListener(new KeyAdapter() {
			public void keyPressed(final KeyEvent e) {
				if (e.getKeyCode() == KeyEvent.VK_ENTER)
					button.doClick();
			}
		});//侦听键盘事件,输完密码后回车就激活登录按钮
		
	}
	
	else{
		type=JOptionPane.ERROR_MESSAGE;
		msg="你没有添加管理员的权限";
		JOptionPane.showMessageDialog(TJGLY.this, msg, "E时代仓库信息管理系统添加管理员提示", type);
		//管理员没有权限管理的权限
	}	
	}
}

⌨️ 快捷键说明

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