📄 createuserdialog.java
字号:
package cn.st.ui;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import cn.st.data.Process;
import cn.st.data.UserBean;
public class CreateUserDialog extends JDialog implements ActionListener {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JPanel jPanel = null;
private JLabel jLuserName = null;
private JTextField jTuserName = null;
private JButton jBenter = null;
private JButton jBcancle = null;
private JLabel jLpassWord = null;
private JPasswordField jPasswordField = null;
private JLabel jLpassword2 = null;
private JPasswordField jPasswordField2 = null;
private final String ENTER = "enter";
private final String CANCLE = "cancel";
private Process process = new Process(); // @jve:decl-index=0:
/**
* @param owner
*/
public CreateUserDialog(Frame owner) {
super(owner);
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(300, 200);
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setModal(true);
this.setContentPane(getJContentPane());
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJPanel(), BorderLayout.CENTER);
}
return jContentPane;
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
jLpassword2 = new JLabel();
jLpassword2.setBounds(new Rectangle(10, 101, 93, 28));
jLpassword2.setText("确认密码:");
jLpassWord = new JLabel();
jLpassWord.setBounds(new Rectangle(10, 58, 93, 28));
jLpassWord.setText("密码:");
jLuserName = new JLabel();
jLuserName.setBounds(new Rectangle(10, 15, 92, 28));
jLuserName.setText("用户名:");
jPanel = new JPanel();
jPanel.setLayout(null);
jPanel.add(jLuserName, null);
jPanel.add(getJTuserName(), null);
jPanel.add(getJBenter(), null);
jPanel.add(getJBcancle(), null);
jPanel.add(jLpassWord, null);
jPanel.add(getJPasswordField(), null);
jPanel.add(jLpassword2, null);
jPanel.add(getJPasswordField2(), null);
}
return jPanel;
}
/**
* This method initializes jTuserName
*
* @return javax.swing.JTextField
*/
private JTextField getJTuserName() {
if (jTuserName == null) {
jTuserName = new JTextField();
jTuserName.setBounds(new Rectangle(115, 15, 157, 28));
}
return jTuserName;
}
/**
* This method initializes jBenter
*
* @return javax.swing.JButton
*/
private JButton getJBenter() {
if (jBenter == null) {
jBenter = new JButton();
jBenter.setBounds(new Rectangle(59, 134, 71, 31));
jBenter.setText("确定");
jBenter.setActionCommand(ENTER);
jBenter.addActionListener(this);
}
return jBenter;
}
/**
* This method initializes jBcancle
*
* @return javax.swing.JButton
*/
private JButton getJBcancle() {
if (jBcancle == null) {
jBcancle = new JButton();
jBcancle.setBounds(new Rectangle(159, 134, 71, 31));
jBcancle.setText("取消");
jBcancle.setActionCommand(CANCLE);
jBcancle.addActionListener(this);
}
return jBcancle;
}
/**
* This method initializes jPasswordField
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getJPasswordField() {
if (jPasswordField == null) {
jPasswordField = new JPasswordField();
jPasswordField.setBounds(new Rectangle(115, 58, 157, 28));
}
return jPasswordField;
}
/**
* This method initializes jPasswordField2
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getJPasswordField2() {
if (jPasswordField2 == null) {
jPasswordField2 = new JPasswordField();
jPasswordField2.setBounds(new Rectangle(115, 102, 157, 27));
}
return jPasswordField2;
}
public static void main(String[] args) {
CreateUserDialog cud = new CreateUserDialog(null);
cud.setVisible(true);
}
public void actionPerformed(ActionEvent arg0) {
String command = arg0.getActionCommand();
if (command.trim().equals(ENTER.trim())) {
String pw1 = new String(this.getJPasswordField().getPassword());
String pw2 = new String(this.getJPasswordField2().getPassword());
if(!pw1.trim().equals(pw2.trim())) {
JOptionPane.showMessageDialog(this,
"两次密码不一致,请重新输入",
"密码错误",
JOptionPane.INFORMATION_MESSAGE);
} else {
UserBean ub = this.process.getUserByName(this.getJTuserName().getText());
if(ub != null) {
JOptionPane.showMessageDialog(this,
"用户已经存在,请重新输入",
"用户已经存在",
JOptionPane.INFORMATION_MESSAGE);
} else {
ub = new UserBean();
ub.setUserName(this.getJTuserName().getText());
ub.setPassword(new String(this.getJPasswordField().getPassword()));
this.process.saveUserBean(ub);
this.dispose();
}
}
} else if (command.trim().equals(CANCLE.trim())) {
this.dispose();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -