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

📄 reguserinfopanel.java

📁 打印管理程序,测试完全通过.windows开发环境.
💻 JAVA
字号:
package jp.co.ntl.swing.ext.cppuser;

import java.awt.Dimension;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SpringLayout;

import jp.co.ntl.Util;
import jp.co.ntl.cppuser.CPPUserInfo;
import jp.co.ntl.swing.ValidatePanel;
import jp.co.ntl.swing.SpringUtilities;
import jp.co.ntl.swing.NumberField;
import jp.co.ntl.swing.ext.DialogManager;
import jp.co.ntl.preference.PreferenceInfo;

public class RegUserInfoPanel extends ValidatePanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public static int				OK_BUTTON;
	public static int				CANCEL_BUTTON;
	
	private JLabel				lblSPKeySerial;
	private NumberField		txtSPKeySerial;
	private JLabel				lblUserID;
	private JTextField			txtUserID;
	
	private CPPUserInfo		userInfo;
	private int				clientKind;
	private Vector				allUserInfos;
	private boolean			modify;

	public RegUserInfoPanel(CPPUserInfo userInfo, boolean modify, Vector allUserInfos) {
		this.userInfo = userInfo;
		this.clientKind = Util.getPreferenceInfo().getClientKind();
		this.allUserInfos = allUserInfos;
		this.modify = modify;
		
		if (clientKind == PreferenceInfo.CLIENT_MAC) {
			OK_BUTTON = 1;
			CANCEL_BUTTON = 0;
		} else {
			OK_BUTTON = 0;
			CANCEL_BUTTON = 1;
		}
		
		setLayout(new SpringLayout());
		
		lblSPKeySerial = new JLabel(Resource.getString(Resource.USER_PANEL_SP_KEY_SERIAL));
		add(lblSPKeySerial);
		
		Dimension	size = new Dimension(200, 24);
		txtSPKeySerial = new NumberField(10, NumberField.UINT);
		txtSPKeySerial.setPreferredSize(size);
		txtSPKeySerial.setMinimumSize(size);
		txtSPKeySerial.setMaximumSize(size);
		add(txtSPKeySerial);
		if (modify) {
			txtSPKeySerial.setEditable(false);
		}
		
		lblUserID = new JLabel(Resource.getString(Resource.USER_PANEL_USER_ID));
		add(lblUserID);
		
		txtUserID = new JTextField();
		txtUserID.setPreferredSize(size);
		txtUserID.setMinimumSize(size);
		txtUserID.setMaximumSize(size);
		add(txtUserID);
		
		SpringUtilities.makeCompactGrid(this, getComponentCount() / 2, 2, 10, 10, 10, 10);
		
		setDefaultButton(OK_BUTTON);
		
		setValuesToComponents();
	}
	
	private void setValuesToComponents() {
		txtSPKeySerial.setText(userInfo.getSPSerial());
		txtUserID.setText(userInfo.getUsername());
	}
	
	private void setValuesFromComponents() {
		userInfo.setSPSerial(txtSPKeySerial.getText());
		userInfo.setUsername(txtUserID.getText());
	}
	
	public boolean isValid(int idxButton) {
		if (idxButton == OK_BUTTON) {
			if (checkItem()) {
				setValuesFromComponents();
			} else {
				return false;
			}
		}
		
		return true;
	}
	
	public JButton[] getButtons() {
		if (clientKind == PreferenceInfo.CLIENT_MAC) {
			return new JButton[] {
					new JButton(Resource.getString(Resource.CANCEL)),
					new JButton(Resource.getString(Resource.REGISTER))
			};
		} else {
			return new JButton[] {
					new JButton(Resource.getString(Resource.REGISTER)),
					new JButton(Resource.getString(Resource.CANCEL))
			};
		}
	}
	
	private boolean checkItem() {
		String		userName = txtUserID.getText();
		String		spSerial = txtSPKeySerial.getText();
		String[]	params;

		if (!modify) {
			for (int i = 0; i < allUserInfos.size(); i++) {
				CPPUserInfo	userInfo = (CPPUserInfo)allUserInfos.elementAt(i);
				if (spSerial.equals(userInfo.getSPSerial())) {
					params = new String[] {
						Resource.getString(Resource.USER_PANEL_SP_KEY_SERIAL)	
					};
					DialogManager.showMessage(this, DialogManager.ERROR_ALREADY_REGISTERED, params);
					return false;
				}
			
				if (userName.equals(userInfo.getUsername())) {
					params = new String[] {
							Resource.getString(Resource.USER_PANEL_USER_ID)
					};
					DialogManager.showMessage(this, DialogManager.ERROR_ALREADY_REGISTERED, params);
					return false;
				}
			}
		}
		return true;
	}
}

⌨️ 快捷键说明

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