⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 removebooks.java

📁 图书管理系统v1.0是使用JAVA语言开发的解决图书基本管理的一个应用程序。 该系统能够实现简单的图书和用户管理
💻 JAVA
字号:
package lib;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class RemoveBooks 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 Books book;

	//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 removeBooks
	public RemoveBooks() {
		//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() {
							book = new Books();
							//for getting the information
							book.connection("SELECT * FROM Books WHERE BookID =" + data);
							int bookID = book.getBookID();
							int numberOfBooks = book.getNumberOfBooks();
							if (bookID > 1) {
								if (numberOfBooks == 1) {
									book.update("DELETE FROM Books WHERE BookID =" + data);
									//for setting JTextField to null
									removeTextField.setText(null);
									JOptionPane.showMessageDialog(null, "数据操作成功!", "信息", JOptionPane.YES_OPTION);
								}
								if (numberOfBooks > 1) {
									numberOfBooks -= 1;
									book.update("UPDATE Books SET NumberOfBooks =" + numberOfBooks +                         
									 " WHERE BookID =" + data);
									//for setting JTextField to null
									removeTextField.setText(null);
									Log log = new Log("\n"+ "RemoveBook :"+","+book.getBookID()+","+book.getSubject()
										+","+book.getTitle()+","+book.getAuthor()+","+book.getPublisher()+","+book.getCopyright()+","+book.getEdition()+","
										+book.getPages()+","+book.getISBN()+","+book.getNumberOfBooks()+","+book.getLibrary());
									JOptionPane.showMessageDialog(null, "数据操作成功!", "信息", JOptionPane.YES_OPTION);
								}
							}
							else
								JOptionPane.showMessageDialog(null, "图书ID号码不正确!", "出错", JOptionPane.ERROR_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 + -