📄 adduser.java
字号:
import java.awt.HeadlessException;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class AddUser extends JDialog implements ActionListener {
private JLabel jLabel1;
private JLabel jLabel2;
private JButton jButton2;
private JButton jButton1;
private JPasswordField jPasswordField1;
private JTextField jTextField1;
private JComboBox jComboBox1;
private JLabel jLabel3;
public AddUser(JFrame frame, String s, boolean b) throws HeadlessException {
super(frame,s,b);
this.setSize(331, 231);
this.setLocation(300, 180);
this.setResizable(false);
setLayout(null);
{
jLabel1 = new JLabel();
getContentPane().add(jLabel1);
jLabel1.setText("\u7528\u6237\u540d");
jLabel1.setBounds(63, 35, 52, 29);
jLabel1.setFont(new java.awt.Font("宋体", 0, 16));
}
{
jLabel2 = new JLabel();
getContentPane().add(jLabel2);
jLabel2.setText("\u5bc6 \u7801");
jLabel2.setBounds(63, 75, 52, 29);
jLabel2.setFont(new java.awt.Font("宋体", 0, 16));
}
{
jLabel3 = new JLabel();
getContentPane().add(jLabel3);
jLabel3.setText("\u6743 \u9650");
jLabel3.setBounds(63, 111, 52, 29);
jLabel3.setFont(new java.awt.Font("宋体", 0, 16));
}
{
ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(
new String[] { "系统管理员", "教师" });
jComboBox1 = new JComboBox();
getContentPane().add(jComboBox1);
jComboBox1.setModel(jComboBox1Model);
jComboBox1.setBounds(121, 114, 137, 22);
}
{
jTextField1 = new JTextField();
getContentPane().add(jTextField1);
jTextField1.setBounds(127, 38, 131, 22);
}
{
jPasswordField1 = new JPasswordField();
getContentPane().add(jPasswordField1);
jPasswordField1.setBounds(127, 78, 131, 22);
}
{
jButton1 = new JButton();
getContentPane().add(jButton1);
jButton1.setText("\u6dfb \u52a0");
jButton1.setBounds(59, 162, 75, 22);
jButton1.addActionListener(this);
}
{
jButton2 = new JButton();
getContentPane().add(jButton2);
jButton2.setText("\u53d6 \u6d88");
jButton2.addActionListener(this);
jButton2.setBounds(181, 162, 77, 22);
}
this.setVisible(true);
validate();
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
Window w = e.getWindow();
w.setVisible(false);
w.dispose();
}
});
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jButton1) {
String name = this.jTextField1.getText().trim();
String password = new String(this.jPasswordField1.getPassword());
String right = this.jComboBox1.getSelectedItem().toString();
Admin admin = new Admin();
admin.setName(name);
admin.setPassword(password);
admin.setRight(right);
StudentManager stm = new StudentManager();
if(stm.insertAdmin(admin)){
JOptionPane.showMessageDialog(this, "添加成功");
this.jTextField1.setText(null);
this.jPasswordField1.setText(null);
this.jComboBox1.setSelectedIndex(0);
}else{
JOptionPane.showMessageDialog(this, "添加失败");
this.jTextField1.setText(null);
this.jPasswordField1.setText(null);
this.jComboBox1.setSelectedIndex(0);
}
}
if (e.getSource() == jButton2) {
this.setVisible(false);
this.dispose();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -