📄 removemembers.java
字号:
package lib;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class RemoveMembers extends JInternalFrame {
/***************************************************************************
*** declaration of the private variables used in the program ***
***************************************************************************/
//for creating the North Panel
private JPanel northPanel = new JPanel();
//for creating the label
private JLabel title = new JLabel("用户信息");
//for creating the Center Panel
private JPanel centerPanel = new JPanel();
//for creating an Internal Panel in the center panel
private JPanel removePanel = new JPanel();
//for creating the label
private JLabel removeLabel = new JLabel(" 填写用户ID: ");
//for creating the text field
private JTextField removeTextField = new JTextField();
//for creating string to store the data
private String data;
//for creating an Internal Panel in the center panel
private JPanel removeMemberPanel = new JPanel();
//for creating the button
private JButton removeButton = new JButton("删除",new ImageIcon(ClassLoader.getSystemResource("images/delete.gif")));
//for creating the South Panel
private JPanel southPanel = new JPanel();
//for adding the button
private JButton exitButton = new JButton("退出",new ImageIcon(ClassLoader.getSystemResource("images/exit.gif")));
//create objects from another classes for using them in the ActionListener
private Members member;
//for checking the information from the text field
public boolean isCorrect() {
if (!removeTextField.getText().equals("")) {
data = removeTextField.getText();
return true;
}
else
return false;
}
//constructor of removeMembers
public RemoveMembers() {
//for setting the title for the internal frame
super("删除用户", false, true, false, true);
//for setting the icon
setFrameIcon(new ImageIcon(ClassLoader.getSystemResource("images/Delete16.gif")));
//for getting the graphical user interface components display area
Container cp = getContentPane();
//for setting the layout
northPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
//for setting the font
title.setFont(new Font("Default", Font.BOLD, 14));
//for adding the label
northPanel.add(title);
//for adding the panel to the container
cp.add("North", northPanel);
//for setting the layout
centerPanel.setLayout(new BorderLayout());
//for setting the layout
removePanel.setLayout(new GridLayout(1, 2, 1, 1));
//for adding the label
removePanel.add(removeLabel);
//for adding the text field
removePanel.add(removeTextField);
//for adding the internal panel to the panel
centerPanel.add("Center", removePanel);
//for setting the layout
removeMemberPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
//for adding the button
removeMemberPanel.add(removeButton);
//for addint the internal panel to the center panel
centerPanel.add("South", removeMemberPanel);
//for setting the border
centerPanel.setBorder(BorderFactory.createTitledBorder("删除用户:"));
//for adding the center panel to the container
cp.add("Center", centerPanel);
/**
*for setting the font for the label & buttons
*/
removeLabel.setFont(new Font("Default", Font.BOLD, 13));
removeTextField.setFont(new Font("Default", Font.PLAIN, 13));
exitButton.setFont(new Font("Default", Font.BOLD, 13));
removeButton.setFont(new Font("Default", Font.BOLD, 13));
//for setting the layout
southPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
//for adding the button
southPanel.add(exitButton);
//for setting the border
southPanel.setBorder(BorderFactory.createEtchedBorder());
//for add the south panel to the container
cp.add("South", southPanel);
/***********************************************************************
* for adding the action listener to the button,first the text will be *
* taken from the JTextField and make the connection for database, *
* after that update the table in the database with the new value *
***********************************************************************/
removeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
//for checking if there is a missing information
if (isCorrect()) {
Thread runner = new Thread() {
public void run() {
member = new Members();
member.connection("SELECT * FROM Members WHERE MemberID = " + data);
//for checking if the user borrowed any book form the library
int numberOfBooks = member.getNumberOfBooks();
if (numberOfBooks == 0&&member.getMoney() == 0) {
member.update("DELETE FROM Members WHERE MemberID = " + data);
//for setting the JTextField to null
removeTextField.setText(null);
Log log = new Log("\n"+"RemoveMembers"+","+member.getMemberID()+","+member.getID()+","+member.getPassword()
+","+member.getName()+","+member.getEmail()+","+member.getMajor()+","+member.getNumberOfBooks()+","
+member.getMoney());
JOptionPane.showMessageDialog(null, "数据操作成功!", "信息", JOptionPane.YES_OPTION);
}
else
if (member.getMoney() == 0 )
JOptionPane.showMessageDialog(null, "该用户有未归还的图书", "警告", JOptionPane.WARNING_MESSAGE);
else
JOptionPane.showMessageDialog(null,"该用户有未缴纳的罚款","警告",JOptionPane.WARNING_MESSAGE);
}
};
runner.start();
}
//if there is a missing data, then display Message Dialog
else {
JOptionPane.showMessageDialog(null, "请填写用户ID", "警告", JOptionPane.WARNING_MESSAGE);
}
}
});
//for adding the action listener for the button to dispose the frame
exitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
dispose();
}
});
//for setting the visible to true
setVisible(true);
//show the internal frame
pack();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -