📄 adduser.java
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import javax.swing.event.*;
public class AddUser implements ActionListener
{
private static AddUser singleton;
private JFrame frame;
private JLabel mlabel;
private JLabel nlabel;
private JLabel alabel;
private JButton ButtonAdd;
private JButton ButtonCancel;
private JTextField name;
private JTextField pwd;
private String[] test;
private FileWriter output;
private Scanner filein;
private JCheckBox admin;
private ManageUsers m;
int Dele;
public AddUser()
{
singleton = this;
//openReadFile();
//creatArray(user);
frame = new JFrame("Add User");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800,600);
frame.setLocationRelativeTo(null);
Container contentPane = frame.getContentPane();
SpringLayout layout = new SpringLayout();
contentPane.setLayout(layout);
mlabel = new JLabel("Add User");
mlabel.setFont(new Font(null,Font.BOLD,32));
nlabel = new JLabel("Name");
ButtonAdd = new JButton(" Add ");
ButtonCancel = new JButton(" Cancel ");
name = new JTextField();
name = new JTextField(15);
alabel = new JLabel("Password");
pwd = new JTextField();
pwd = new JTextField(15);
admin = new JCheckBox("Administrator", false);
contentPane.add(mlabel);
contentPane.add(nlabel);
contentPane.add(ButtonAdd);
contentPane.add(ButtonCancel);
contentPane.add(name);
contentPane.add(alabel);
contentPane.add(pwd);
contentPane.add(admin);
layout.putConstraint(SpringLayout.WEST, mlabel,
320,
SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, mlabel,
20,
SpringLayout.NORTH, contentPane);
layout.putConstraint(SpringLayout.WEST, name,
70,
SpringLayout.WEST, nlabel);
layout.putConstraint(SpringLayout.NORTH, name,
185,
SpringLayout.SOUTH, mlabel);
layout.putConstraint(SpringLayout.WEST, nlabel,
280,
SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, nlabel,
185,
SpringLayout.SOUTH, mlabel);
layout.putConstraint(SpringLayout.WEST, alabel,
280,
SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, alabel,
30,
SpringLayout.NORTH, nlabel);
layout.putConstraint(SpringLayout.WEST, pwd,
70,
SpringLayout.WEST, alabel);
layout.putConstraint(SpringLayout.NORTH, pwd,
30,
SpringLayout.NORTH, nlabel);
layout.putConstraint(SpringLayout.WEST, admin,
280,
SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, admin,
30,
SpringLayout.NORTH, alabel);
layout.putConstraint(SpringLayout.EAST, ButtonAdd,
-30,
SpringLayout.WEST, ButtonCancel);
layout.putConstraint(SpringLayout.NORTH, ButtonAdd,
500,
SpringLayout.NORTH, contentPane);
layout.putConstraint(SpringLayout.EAST, ButtonCancel,
-50,
SpringLayout.EAST, contentPane);
layout.putConstraint(SpringLayout.NORTH, ButtonCancel,
500,
SpringLayout.NORTH, contentPane);
ButtonAdd.addActionListener(this);
admin.addActionListener(this);
ButtonCancel.addActionListener(this);
makeVisible();
}
public void makeVisible()
{
frame.setVisible(true);
frame.setResizable(false);
}
public static void show()
{
if (!(singleton == null)) { singleton.makeVisible(); } else { singleton = new AddUser(); }
}
public void actionPerformed (ActionEvent e)
{
if (e.getSource().equals(ButtonAdd))
{
String n = name.getText();
String p = pwd.getText();
boolean ad = admin.isSelected();
CreateSquentialFile ATCUsers = new CreateSquentialFile(n, p, ad, new ArrayList<Result>());
ATCUsers.openFile();
ATCUsers.addUserRecord();
ATCUsers.closeFile();
//User user3 = new User(n, p, ad, new ArrayList<Result>());
ManageUsers.show();
frame.setVisible(false);
}
if (e.getSource().equals(ButtonCancel)) { ManageUsers.show(); frame.setVisible(false); }
}
public void creatArray(ArrayList<String> user)
{
int n = user.size();
test = new String[n];
for(int i = 0; i < n; i++)
{
test[i] = user.get(i);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -