【Java开源代码栏目提醒】:网学会员Java开源代码为您提供AddOperator.java参考,解决您在AddOperator.java学习中工作中的难题,参考学习。
package com.costumemanager.operator;
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 javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import dataBaseConnection.*;
import model.*;
public class AddOperator extends JPanel {
private JTextField loginName; // 登录名称(用户名)
private JPasswordField passwordField2; // 密码框(第二次输入)
private JPasswordField passwordField; // 密码框(第一次输入)
private JComboBox operatorType; // 操作员类型
private Dao dao = new Dao();
private void clear() {
loginName.setText(null);
// name.setText(null);
passwordField2.setText(null);
passwordField.setText(null);
}
public AddOperator() {
super();
setLayout(new GridBagLayout());
setBounds(0, 0, 280, 236);
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.gridx = 0;
gridBagConstraints_10.gridy = 0;
add(label_4, gridBagConstraints_10);
loginName = 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 = 0;
gridBagConstraints_11.gridx = 1;
add(loginName, gridBagConstraints_11);
final JLabel label = new JLabel();
label.setFont(new Font("", Font.PLAIN, 14));
label.setText("类型:");
final GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridy = 1;
gridBagConstraints.gridx = 0;
add(label, gridBagConstraints);
operatorType = new JComboBox();
operatorType.setFont(new Font("", Font.PLAIN, 14));
initTypeBox();// 初始化类型
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 = 1;
gridBagConstraints_1.gridx = 1;
add(operatorType, gridBagConstraints_1);
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);
passwordField2 = 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(passwordField2, gridBagConstraints_7);
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
String tbName = loginName.getText();
// String tbUsername = name.getText();
String password = new String(passwordField.getPassword());
String password1 = new String(passwordField2.getPassword());
Account user = dao.getUser(tbName, password);
if (user.getAccountName() != null
&& !user.getAccountName().isEmpty()) {
JOptionPane
.showMessageDialog(AddOperator.this, "此登录名称已经存在");
operatorType.setFocusable(true);
return;
}
if (passwordField.getPassword().length == 0) {
JOptionPane.showMessageDialog(AddOperator.this, "密码不能为空");
} else if (password.equals(password1)) {
Account tbUserlist = new Account();
// tbUserlist.setAccountType(2);
if (operatorType.getSelectedItem().toString().trim().equals("操作员")) {
tbUserlist.setAccountType(1);
} else if (operatorType.getSelectedItem().toString().trim().equals(
"销售员")) {
tbUserlist.setAccountType(2);
} else if (operatorType.getSelectedItem().toString().trim().equals(
"仓库管理员")) {
tbUserlist.setAccountType(3);
}
tbUserlist.setAccountPassword(password1);
tbUserlist.setAccountName(loginName.getText().trim());
// tbUserlist.setManagerId(Integername.getText().trim());
if (dao.addUser(tbUserlist) == 1) {
JOptionPane.showMessageDialog(AddOperator.this,
"操作员添加成功");
clear();
} else {
JOptionPane.showMessageDialog(AddOperator.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);
}
// 初始化单位下
上一篇:
addNodeInJTree.java
下一篇:
法律专业开题报告范文