📄 mainframe.java
字号:
/**
* This method initializes searchTextField
*
* @return javax.swing.JTextField
*/
private JTextField getSearchTextField() {
if (searchTextField == null) {
searchTextField = new JTextField();
searchTextField.setPreferredSize(new Dimension(6, 21));
searchTextField.setColumns(40);
}
return searchTextField;
}
/**
* This method initializes searchButton
*
* @return javax.swing.JButton
*/
private JButton getSearchButton() {
if (searchButton == null) {
searchButton = new JButton();
searchButton.setText("查询");
searchButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
String condition = searchTextField.getText();
userTable.setModel(new UserTableModel(condition));
}
});
}
return searchButton;
}
/**
* This method initializes userInfoPanel
*
* @return javax.swing.JPanel
*/
private JPanel getUserInfoPanel() {
if (userInfoPanel == null) {
GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
gridBagConstraints3.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints3.gridy = 1;
gridBagConstraints3.weightx = 1.0;
gridBagConstraints3.gridx = 3;
GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints1.gridx = 1;
gridBagConstraints1.gridy = 1;
gridBagConstraints1.weightx = 1.0;
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.anchor = GridBagConstraints.CENTER;
gridBagConstraints.gridy = 1;
userInfoPanel = new JPanel();
userInfoPanel.setLayout(new BorderLayout());
userInfoPanel.add(getInputPanel(), BorderLayout.CENTER);
userInfoPanel.add(getBtnPanel(), BorderLayout.SOUTH);
}
return userInfoPanel;
}
/**
* This method initializes bookPanel1
*
* @return javax.swing.JPanel
*/
private JPanel getBookPanel1() {
if (bookPanel1 == null) {
bookPanel1 = new JPanel();
bookPanel1.setLayout(new BorderLayout());
bookPanel1.add(getBookmainScrollPane(), BorderLayout.CENTER);
bookPanel1.add(getBookInfoPanel(), BorderLayout.SOUTH);
bookPanel1.add(getBooksearchPanel(), BorderLayout.NORTH);
}
return bookPanel1;
}
/**
* This method initializes jPanel1
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel1() {
if (jPanel1 == null) {
jPanel1 = new JPanel();
jPanel1.setLayout(new GridBagLayout());
}
return jPanel1;
}
/**
* This method initializes inputPanel
*
* @return javax.swing.JPanel
*/
private JPanel getInputPanel() {
if (inputPanel == null) {
GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
gridBagConstraints4.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints4.gridy = 1;
gridBagConstraints4.weightx = 1.0;
gridBagConstraints4.gridx = 1;
GridBagConstraints gridBagConstraints15 = new GridBagConstraints();
gridBagConstraints15.gridx = 0;
gridBagConstraints15.ipadx = 83;
gridBagConstraints15.ipady = 6;
gridBagConstraints15.gridwidth = 4;
gridBagConstraints15.gridy = 0;
GridBagConstraints gridBagConstraints14 = new GridBagConstraints();
gridBagConstraints14.fill = GridBagConstraints.VERTICAL;
gridBagConstraints14.gridx = 3;
gridBagConstraints14.gridy = 3;
gridBagConstraints14.ipadx = 125;
gridBagConstraints14.weightx = 1.0;
gridBagConstraints14.insets = new Insets(0, 0, 0, 3);
GridBagConstraints gridBagConstraints13 = new GridBagConstraints();
gridBagConstraints13.gridx = 2;
gridBagConstraints13.ipadx = 71;
gridBagConstraints13.ipady = 6;
gridBagConstraints13.gridy = 3;
GridBagConstraints gridBagConstraints12 = new GridBagConstraints();
gridBagConstraints12.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints12.gridy = 3;
gridBagConstraints12.ipadx = 125;
gridBagConstraints12.weightx = 1.0;
gridBagConstraints12.gridx = 1;
GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
gridBagConstraints11.gridx = 0;
gridBagConstraints11.ipadx = 95;
gridBagConstraints11.ipady = 6;
gridBagConstraints11.gridy = 3;
GridBagConstraints gridBagConstraints10 = new GridBagConstraints();
gridBagConstraints10.fill = GridBagConstraints.VERTICAL;
gridBagConstraints10.gridx = 3;
gridBagConstraints10.gridy = 2;
gridBagConstraints10.ipadx = 125;
gridBagConstraints10.weightx = 1.0;
gridBagConstraints10.insets = new Insets(0, 0, 0, 3);
GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
gridBagConstraints9.gridx = 2;
gridBagConstraints9.ipadx = 95;
gridBagConstraints9.ipady = 6;
gridBagConstraints9.gridy = 2;
GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
gridBagConstraints8.gridx = 1;
gridBagConstraints8.ipadx = 89;
gridBagConstraints8.gridy = 2;
GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
gridBagConstraints7.gridx = 0;
gridBagConstraints7.ipadx = 95;
gridBagConstraints7.ipady = 6;
gridBagConstraints7.gridy = 2;
GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
gridBagConstraints6.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints6.gridx = 3;
gridBagConstraints6.gridy = 1;
gridBagConstraints6.ipadx = 5;
gridBagConstraints6.weightx = 1.0;
gridBagConstraints6.insets = new Insets(0, 0, 0, 3);
GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
gridBagConstraints5.gridx = 2;
gridBagConstraints5.ipadx = 95;
gridBagConstraints5.ipady = 6;
gridBagConstraints5.gridy = 1;
GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
gridBagConstraints2.gridx = 0;
gridBagConstraints2.ipadx = 89;
gridBagConstraints2.ipady = 6;
gridBagConstraints2.gridy = 1;
msgLabel = new JLabel();
msgLabel.setHorizontalAlignment(SwingConstants.LEADING);
msgLabel.setText("用户信息");
msgLabel.setHorizontalTextPosition(SwingConstants.CENTER);
user_descLabel = new JLabel();
user_descLabel.setText("\u7528\u6237\u8bf4\u660e\uff1a");
addressLabel = new JLabel();
addressLabel.setText("\u5730\u5740\uff1a");
birthLabel = new JLabel();
birthLabel.setText("\u751f\u65e5\uff1a");
genderLabel = new JLabel();
genderLabel.setText("\u6027\u522b\uff1a");
passwoedLabel = new JLabel();
passwoedLabel.setText("\u5bc6\u7801\uff1a");
usernameLabel = new JLabel();
usernameLabel.setText("\u7528\u6237\u540d:");
inputPanel = new JPanel();
inputPanel.setLayout(new GridBagLayout());
inputPanel.add(usernameLabel, gridBagConstraints2);
inputPanel.add(passwoedLabel, gridBagConstraints5);
inputPanel.add(getPasswordField(), gridBagConstraints6);
inputPanel.add(genderLabel, gridBagConstraints7);
inputPanel.add(getGenderjPanel(), gridBagConstraints8);
inputPanel.add(birthLabel, gridBagConstraints9);
inputPanel.add(getBirthTextField(), gridBagConstraints10);
inputPanel.add(addressLabel, gridBagConstraints11);
inputPanel.add(getAddressTextField(), gridBagConstraints12);
inputPanel.add(user_descLabel, gridBagConstraints13);
inputPanel.add(getUser_descTextField(), gridBagConstraints14);
inputPanel.add(msgLabel, gridBagConstraints15);
inputPanel.add(getUsernameTextField(), gridBagConstraints4);
}
return inputPanel;
}
/**
* This method initializes btnPanel
*
* @return javax.swing.JPanel
*/
private JPanel getBtnPanel() {
if (btnPanel == null) {
btnPanel = new JPanel();
btnPanel.setLayout(new FlowLayout());
btnPanel.add(getAddButton(), null);
btnPanel.add(getUpdateButton(), null);
btnPanel.add(getDeleteButton(), null);
}
return btnPanel;
}
/**
* This method initializes updateButton
*
* @return javax.swing.JButton
*/
private JButton getUpdateButton() {
if (updateButton == null) {
updateButton = new JButton();
updateButton.setText("修改");
updateButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
int selectedRow = userTable.getSelectedRow();
UserTableModel model = (UserTableModel) userTable.getModel();
String id = ((String) model.getValueAt(selectedRow, 0));
String username = usernameTextField.getText();
String password = String.copyValueOf(PasswordField.getPassword());
String gender = "m";
if (femaleRadioButton.isSelected()) {
gender = "f";
}
// String birthday = new
// SimpleDateFormat("yyyy-MM-dd").format(birthTextField.getDate());
Date birthday = birthTextField.getDate();
// String birthday = birthTextField.getText();
String address = addressTextField.getText();
String user_desc = user_descTextField.getText();
int number = UserDao.updateUser(id, username, password,
gender, birthday, address, user_desc);
System.out.println(number);
userTable.setModel(new UserTableModel());
msgLabel.setText("更新成功!");
}
});
}
return updateButton;
}
/**
* This method initializes PasswordField
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getPasswordField() {
if (PasswordField == null) {
PasswordField = new JPasswordField();
PasswordField.setColumns(20);
}
return PasswordField;
}
/**
* This method initializes birthTextField
*
* @return javax.swing.JTextField
*/
private JXDatePicker getBirthTextField() {
if (birthTextField == null) {
birthTextField = new JXDatePicker();
String[] formats = { "yyyy-MM-dd" };
birthTextField.setFormats(formats);
JXMonthView monthview = birthTextField.getMonthView();
String[] days = { "日 ", "一", "二", "三", "四", "五", "六" };
monthview.setDaysOfTheWeek(days);
monthview.setFirstDayOfWeek(Calendar.MONDAY);
birthTextField.setLinkDay(new Date(), "今天是{0,date,yyyy-MM-dd}");
}
return birthTextField;
}
/**
* This method initializes addressTextField
*
* @return javax.swing.JTextField
*/
private JTextField getAddressTextField() {
if (addressTextField == null) {
addressTextField = new JTextField();
}
return addressTextField;
}
/**
* This method initializes user_descTextField
*
* @return javax.swing.JTextField
*/
private JTextField getUser_descTextField() {
if (user_descTextField == null) {
user_descTextField = new JTextField();
}
return user_descTextField;
}
/**
* This method initializes genderjPanel
*
* @return javax.swing.JPanel
*/
private JPanel getGenderjPanel() {
if (genderjPanel == null) {
genderjPanel = new JPanel();
genderjPanel.setLayout(new BoxLayout(getGenderjPanel(),
BoxLayout.X_AXIS));
genderjPanel.add(getMaleRadioButton(), null);
genderjPanel.add(getFemaleRadioButton(), null);
ButtonGroup gendergroup = new ButtonGroup();
gendergroup.add(maleRadioButton);
gendergroup.add(femaleRadioButton);
}
return genderjPanel;
}
/**
* This method initializes maleRadioButton
*
* @return javax.swing.JRadioButton
*/
private JRadioButton getMaleRadioButton() {
if (maleRadioButton == null) {
maleRadioButton = new JRadioButton();
maleRadioButton.setText("男");
maleRadioButton.setSelected(true);
}
return maleRadioButton;
}
/**
* This method initializes femaleRadioButton
*
* @return javax.swing.JRadioButton
*/
private JRadioButton getFemaleRadioButton() {
if (femaleRadioButton == null) {
femaleRadioButton = new JRadioButton();
femaleRadioButton.setText("女");
}
return femaleRadioButton;
}
/**
* This method initializes usernameTextField
*
* @return javax.swing.JTextField
*/
private JTextField getUsernameTextField() {
if (usernameTextField == null) {
usernameTextField = new JTextField();
}
return usernameTextField;
}
/**
* This method initializes rightPopupMenu
*
* @return javax.swing.JPopupMenu
*/
private JPopupMenu getRightPopupMenu() {
if (rightPopupMenu == null) {
rightPopupMenu = new JPopupMenu();
rightPopupMenu.add(getAddMenuItem());
rightPopupMenu.add(getUpdateMenuItem());
rightPopupMenu.add(getDeleteMenuItem());
isSelectStatus(isSelect);
}
return rightPopupMenu;
}
/**
* This method initializes addMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getAddMenuItem() {
if (addMenuItem == null) {
addMenuItem = new JMenuItem();
addMenuItem.setText("增加");
addMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
// String username = usernameTextField.getText();
// String password =
// String.valueOf(PasswordField.getPassword());
// String gender = "m";
// if(femaleRadioButton.isSelected()){
// gender= "f";
// }
// // String birthday = new
// SimpleDateFormat("yyyy-MM-dd").format(birthTextField.getDate());
// String birthday = birthTextField.getText();
// String address = addressTextField.getText();
// String user_desc = user_descTextField.getText();
// if(username.equals("")){
// usernameTextField.setBackground(Color.pink);
// msgLabel.setText("请输入用户名");
// return;
// }
// int number = UserDao.userInsert(username,
// password,gender,birthday,address,user_desc);
// System.out.println(number);
// msgLabel.setText("添加成功!");
new AddUserFrame().setVisible(true);
}
});
}
return addMenuItem;
}
/**
* This method initializes updateMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getUpdateMenuItem() {
if (updateMenuItem == null) {
updateMenuItem = new JMenuItem();
updateMenuItem.setText("修改");
updateMenuItem
.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
int selectedRow = userTable.getSelectedRow();
UserTableModel model = (UserTableModel) userTable
.getModel();
String id = ((String) model.getValueAt(selectedRow,
0));
String username = usernameTextField.getText();
String password = String.copyValueOf(PasswordField
.getPassword());
String gender = "m";
if (femaleRadioButton.isSelected()) {
gender = "f";
}
// String birthday = new
// SimpleDateFormat("yyyy-MM-dd").format(birthTextField.getDate());
Date birthday = birthTextField.getDate();
// String birthday = birthTextField.getText();
String address = addressTextField.getText();
String user_desc = user_descTextField.getText();
int number = UserDao.updateUser(id, username,
password, gender, birthday, address,
user_desc);
System.out.println(number);
msgLabel.setText("更新成功!");
}
});
}
return updateMenuItem;
}
/**
* This method initializes deleteMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getDeleteMenuItem() {
if (deleteMenuItem == null) {
deleteMenuItem = new JMenuItem();
deleteMenuItem.setText("删除");
deleteMenuItem
.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
int selectedRow = userTable.getSelectedRow();
UserTableModel model = (UserTableModel) userTable
.getModel();
String id = ((String) model.getValueAt(selectedRow,
0));
int number = UserDao.deleteUser(id);
System.out.println(number);
deleteMenuItem.setEnabled(false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -