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

📄 addnewuserjpanel.java

📁 连接测试系统
💻 JAVA
字号:
package com.cnu.cie.olts.client.admin;import java.awt.Dimension;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.IOException;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;import javax.swing.ComboBoxModel;import javax.swing.DefaultComboBoxModel;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JOptionPane;import javax.swing.WindowConstants;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPasswordField;import javax.swing.JTextField;import com.cnu.cie.olts.client.Login;/*** This code was edited or generated using CloudGarden's Jigloo* SWT/Swing GUI Builder, which is free for non-commercial* use. If Jigloo is being used commercially (ie, by a corporation,* company or business for any purpose whatever) then you* should purchase a license for each developer using Jigloo.* Please visit www.cloudgarden.com for details.* Use of Jigloo implies acceptance of these licensing terms.* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.*/public class AddNewUserJPanel extends javax.swing.JPanel {	private JLabel usernamejLabel;	private JTextField userNamejTextField;	private JPasswordField twojPasswordField;	private JPasswordField onejPasswordField;	private JButton submitjButton;	private JComboBox statusjComboBox;	private JLabel statusjLabel;	private JLabel passwordTwojLabel;	private JLabel passwordOnejLabel;	/**	* Auto-generated main method to display this 	* JPanel inside a new JFrame.	*/	public static void main(String[] args) {		JFrame frame = new JFrame();		frame.getContentPane().add(new AddNewUserJPanel());		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);		frame.pack();		frame.setVisible(true);	}		public AddNewUserJPanel() {		super();		initGUI();	}		private void initGUI() {		try {			setPreferredSize(new Dimension(509, 371));			this.setLayout(null);			{				usernamejLabel = new JLabel();				this.add(usernamejLabel);				usernamejLabel.setText("\u7528\u6237\u540d");				usernamejLabel.setBounds(102, 67, 71, 21);			}			{				userNamejTextField = new JTextField();				this.add(userNamejTextField);				userNamejTextField.setBounds(183, 66, 153, 24);			}			{				passwordOnejLabel = new JLabel();				this.add(passwordOnejLabel);				passwordOnejLabel.setText("\u5bc6\u7801");				passwordOnejLabel.setBounds(102, 119, 71, 23);			}			{				passwordTwojLabel = new JLabel();				this.add(passwordTwojLabel);				passwordTwojLabel.setText("\u91cd\u590d\u5bc6\u7801");				passwordTwojLabel.setBounds(102, 177, 71, 22);			}			{				statusjLabel = new JLabel();				this.add(statusjLabel);				statusjLabel.setText("\u8eab\u4efd");				statusjLabel.setBounds(102, 227, 71, 23);			}			{				ComboBoxModel statusjComboBoxModel = 					new DefaultComboBoxModel(							new String[] { "学生", "教师" ,"管理员" });				statusjComboBox = new JComboBox();				this.add(statusjComboBox);				statusjComboBox.setModel(statusjComboBoxModel);				statusjComboBox.setBounds(185, 224, 121, 28);			}			{				submitjButton = new JButton();				this.add(submitjButton);				submitjButton.setText("\u63d0  \u4ea4");				submitjButton.setBounds(152, 305, 95, 28);				submitjButton.addActionListener(new ActionListener() {					public void actionPerformed(ActionEvent evt) {						submitjButtonActionPerformed(evt);					}				});			}			{				onejPasswordField = new JPasswordField();				this.add(onejPasswordField);				onejPasswordField.setBounds(183, 119, 153, 23);			}			{				twojPasswordField = new JPasswordField();				this.add(twojPasswordField);				twojPasswordField.setBounds(185, 177, 151, 24);			}		} catch (Exception e) {			e.printStackTrace();		}	}		private void submitjButtonActionPerformed(ActionEvent evt) {		//System.out.println("submitjButton.actionPerformed, event="+evt);		//TODO add your code for submitjButton.actionPerformed		String username,passwordone,passwordtwo,status;		username=userNamejTextField.getText().trim();		passwordone=onejPasswordField.getText().trim();		passwordtwo=twojPasswordField.getText().trim();		status=statusjComboBox.getSelectedItem().toString();		if("".equals(username)){	  		JOptionPane.showMessageDialog(null,"用户名不能为空","联机测试系统",JOptionPane.ERROR_MESSAGE);	  		return;	  	}	  	if("".equals(passwordone)){	  		JOptionPane.showMessageDialog(null,"密码不能为空","联机测试系统",JOptionPane.ERROR_MESSAGE);	  		return;	  	}		  	if("".equals(passwordtwo)){	  		JOptionPane.showMessageDialog(null,"重复密码不能为空","联机测试系统",JOptionPane.ERROR_MESSAGE);	  		return;	  	}	  	if(!passwordone.equals(passwordtwo)){	  		JOptionPane.showMessageDialog(null,"两次密码不一样","联机测试系统",JOptionPane.ERROR_MESSAGE);	  		return;	  	}	  	//md5加密	//  	byte[]   data   =passwordone.getBytes();	//	MessageDigest md = null;	//	try {	//		md = MessageDigest.getInstance("MD5");	//	} catch (NoSuchAlgorithmException e1) {	//		// TODO Auto-generated catch block	//		e1.printStackTrace();	//		JOptionPane.showMessageDialog(null,"md5密钥产生失败","联机测试系统",JOptionPane.ERROR_MESSAGE);	//		return ;	//	}   	//	passwordone   =   new String(md.digest(data)); 	  			String infotoserver="ADDNEWUSER:insert into user_info(username,password,status) "+		"values('"+username+"','"+passwordone+"','"+status+"')";		AdminFrame.pswriter.println(infotoserver);		AdminFrame.pswriter.flush();		String returninfo = null;		  try {			returninfo=AdminFrame.bufreader.readLine();		} catch (IOException e) {			// TODO Auto-generated catch block			e.printStackTrace();			JOptionPane.showMessageDialog(null,"与服务器的连接已经中断,请重新连接","连接中断",JOptionPane.ERROR_MESSAGE);			AdminFrame.reconnectButton.setEnabled(true);			AdminFrame.reconnectMenuItem.setEnabled(true);			return;		}		if(returninfo==null){			JOptionPane.showMessageDialog(null,"与服务器的连接已经中断,请重新连接","连接中断",JOptionPane.ERROR_MESSAGE);			AdminFrame.reconnectButton.setEnabled(true);			AdminFrame.reconnectMenuItem.setEnabled(true);			return ;		}		if("ADDUSERSUCC".equals(returninfo)){			JOptionPane.showMessageDialog(null,"新用户添加成功","联机测试系统",JOptionPane.ERROR_MESSAGE);		}		else if("ADDUSERFAIL".equals(returninfo)){			JOptionPane.showMessageDialog(null,"新用户添加失败,请重试","联机测试系统",JOptionPane.ERROR_MESSAGE);			return ;		}		submitjButton.setEnabled(false);		System.out.println("username---"+username);		System.out.println("passwordone---"+passwordone);		System.out.println("passwordtwo---"+passwordtwo);		System.out.println("status---"+status);	}}

⌨️ 快捷键说明

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