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

📄 swingui.java

📁 一个图书管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				switch (querybrw_cbx.getSelectedIndex()) {

				case 0:
					String bookID = textField.getText();
					book = bookManager.searchByID(bookID);
					break;

				case 1:
					String bookName = textField.getText();
					book = bookManager.searchByName(bookName);
					break;

				}
				if (book == null) {

					JOptionPane.showMessageDialog(null, "没有此书");

				} else {
					Vector rowData = new Vector();
					Vector row = new Vector();
					row.add(book.getBookId());
					row.add(book.getBookName());
					row.add(book.getAuthor());
					row.add(book.getPrice());
					row.add(book.getPublishingHouse());
					rowData.add(row);

					Vector columnNames = new Vector();
					columnNames.add("书编号");
					columnNames.add("书名");
					columnNames.add("作者");
					columnNames.add("价格");
					columnNames.add("出版社");

					JTable table = new JTable(rowData, columnNames);
					JScrollPane jpanel = new JScrollPane(table);
					jpanel.setBounds(5, 90, 480, 200);
					panel.add(jpanel);
					textField.setText(null);
				}
			}

		};
		button.addActionListener(actionListener);

		frame.setContentPane(panel);
		frame.validate();

	}

	// 显示所有书

	public void getAll() throws Exception {
		Vector rowData = new Vector();

		List list = bookManager.getAll();

		Iterator it = list.iterator();
		while (it.hasNext()) {
			Book book = (Book) it.next();
			Vector row = new Vector();
			row.add(book.getBookId());
			row.add(book.getBookName());
			row.add(book.getAuthor());
			row.add(book.getPrice());
			row.add(book.getPublishingHouse());
			rowData.add(row);
		}
		Vector columnNames = new Vector();
		columnNames.add("书编号");
		columnNames.add("书名");
		columnNames.add("作者");
		columnNames.add("价格");
		columnNames.add("出版社");

		JTable table = new JTable(rowData, columnNames);
		JScrollPane panel = new JScrollPane(table);

		frame.setContentPane(panel);
		frame.validate();

	}

	// 增加会员
	public void addUser() throws Exception {

		final JPanel panel = new JPanel();
		panel.setLayout(null);
		panel.setBounds(0, 0, 490, 347);
		getContentPane().add(panel);

		final JLabel label = new JLabel();
		label.setText("会员编号");
		label.setBounds(120, 50, 60, 30);
		panel.add(label);

		final JLabel label_1 = new JLabel();
		label_1.setText("会员名");
		label_1.setBounds(120, 90, 60, 30);
		panel.add(label_1);

		final JTextField textField = new JTextField(10);
		textField.setBounds(200, 50, 165, 30);
		panel.add(textField);

		final JTextField textField1 = new JTextField(10);
		textField1.setBounds(200, 90, 165, 30);
		panel.add(textField1);

		final JButton button = new JButton();
		button.setText("提交");
		button.setBounds(137, 255, 80, 30);
		panel.add(button);

		final JButton button_1 = new JButton();
		button_1.setText("重置");
		button_1.setBounds(272, 255, 80, 30);
		panel.add(button_1);

		frame.setContentPane(panel);
		frame.validate();

		ActionListener btListener = new ActionListener() {

			public void actionPerformed(ActionEvent e) {

				JButton bt = (JButton) e.getSource();
				if (bt == button) {
					User user = new User();
					user.setUserId(textField.getText());
					user.setUserName(textField1.getText());

					JOptionPane.showMessageDialog(null, userManager
							.addUser(user));

					textField.setText(null);
					textField1.setText(null);

				}
				if (bt == button_1) {
					textField.setText(null);
					textField1.setText(null);

				}
			}
		};
		button_1.addActionListener(btListener);
		button.addActionListener(btListener);

	}

	// 删除会员
	public void deleteUser() throws Exception {

		final JPanel panel = new JPanel();
		panel.setLayout(null);
		panel.setBounds(0, 0, 490, 347);
		frame.add(panel);

		final JLabel label = new JLabel();
		label.setText("会员编号");
		label.setBounds(70, 50, 95, 25);
		panel.add(label);

		final JTextField textField = new JTextField();
		textField.setBounds(160, 50, 190, 25);
		panel.add(textField);

		final JButton button = new JButton();
		button.setText("提交");
		button.setBounds(390, 50, 60, 25);
		panel.add(button);

		ActionListener actionListener = new ActionListener() {

			public void actionPerformed(ActionEvent e) {

				String userId = textField.getText();

				JOptionPane.showMessageDialog(null, userManager
						.deleteUser(userId));

				textField.setText(null);
			}

		};

		button.addActionListener(actionListener);

		frame.setContentPane(panel);
		frame.validate();
	}

	// 查找会员
	public void searchUsUserName() throws Exception {

		final JPanel panel = new JPanel();
		panel.setLayout(null);
		panel.setBounds(0, 0, 490, 347);
		getContentPane().add(panel);

		String[] items = new String[] { "会员编号", "会员名称","查找所有会员" };
		final JComboBox querybrw_cbx = new JComboBox(items);
		querybrw_cbx.setBounds(55, 50, 95, 30);
		panel.add(querybrw_cbx);

		final JTextField textField = new JTextField();
		textField.setBounds(160, 50, 195, 30);
		panel.add(textField);

		final JButton button = new JButton();
		button.setText("提交");
		button.setBounds(365, 50, 60, 30);
		panel.add(button);

		final JScrollPane scrollPane = new JScrollPane();
		panel.add(scrollPane);
		scrollPane.setBounds(5, 90, 480, 200);

		final JTable table = new JTable();
		scrollPane.setViewportView(table);

		ActionListener actionListener = new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				User user = null;
				List list = null;
				Vector rowData = new Vector();
				Vector row = new Vector();
				Vector columnNames = new Vector();
				switch (querybrw_cbx.getSelectedIndex()) {

				case 0:
					String userID = textField.getText();
					user = userManager.searchUsID(userID);
					break;

				case 1:
					String userName = textField.getText();
					user = userManager.searchUsName(userName);
					break;
				case 2:
					list = userManager.getAll();
					break;
				}
				if (list == null&& user == null) {
					if (user == null) {

						JOptionPane.showMessageDialog(null, "没有此会员");

					} else {
						row.add(user.getUserId());
						row.add(user.getUserName());
						rowData.add(row);
		
					}
				}else{
					Iterator it = list.iterator();
					while (it.hasNext()) {
						user = (User) it.next();
						row.add(user.getUserId());
						row.add(user.getUserName());
						rowData.add(row);
						
					}
					
				}

				columnNames.add("会员编号");
				columnNames.add("会员名字");

				JTable table = new JTable(rowData, columnNames);
				JScrollPane jpanel = new JScrollPane(table);
				jpanel.setBounds(5, 90, 480, 200);
				panel.add(jpanel);
				textField.setText(null);
			}

		};
		button.addActionListener(actionListener);

		frame.setContentPane(panel);
		frame.validate();

	}

	// 借书
	public void addBorrow() throws Exception {

		final JPanel panel = new JPanel();
		panel.setLayout(null);
		panel.setBounds(0, 0, 490, 347);
		getContentPane().add(panel);

		final JLabel label = new JLabel();
		label.setText("借书编号");
		label.setBounds(120, 50, 60, 30);
		panel.add(label);

		final JLabel label_1 = new JLabel();
		label_1.setText("会员编号");
		label_1.setBounds(120, 90, 60, 30);
		panel.add(label_1);

		final JLabel label_2 = new JLabel();
		label_2.setText("书编号");
		label_2.setBounds(120, 130, 60, 30);
		panel.add(label_2);

		final JTextField textField = new JTextField(10);
		textField.setBounds(200, 50, 165, 30);
		panel.add(textField);

		final JTextField textField1 = new JTextField(10);
		textField1.setBounds(200, 90, 165, 30);
		panel.add(textField1);

		final JTextField textField2 = new JTextField(10);
		textField2.setBounds(200, 130, 165, 30);
		panel.add(textField2);

		final JButton button = new JButton();
		button.setText("提交");
		button.setBounds(137, 255, 80, 30);
		panel.add(button);

		final JButton button_1 = new JButton();
		button_1.setText("重置");
		button_1.setBounds(272, 255, 80, 30);
		panel.add(button_1);

		frame.setContentPane(panel);
		frame.validate();

		ActionListener btListener = new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				Borrow borrow = new Borrow();
				JButton bt = (JButton) e.getSource();
				if (bt == button) {

					borrow.setBorrowID(textField.getText());
					borrow
							.setUser(userManager.searchUsID(textField1
									.getText()));
					borrow
							.setBook(bookManager.searchByID(textField2
									.getText()));

					JOptionPane.showMessageDialog(null, borrowManager
							.addBorrow(borrow));

					textField.setText(null);
					textField1.setText(null);
					textField2.setText(null);

				}
				if (bt == button_1) {
					textField.setText(null);
					textField1.setText(null);
					textField2.setText(null);

				}
			}
		};
		button_1.addActionListener(btListener);
		button.addActionListener(btListener);
	}

	// 还书
	public void deleteBorrow() throws Exception {

		final JPanel panel = new JPanel();
		panel.setLayout(null);
		panel.setBounds(0, 0, 490, 347);
		frame.add(panel);

		final JLabel label = new JLabel();
		label.setText("借书编号");
		label.setBounds(70, 50, 95, 25);
		panel.add(label);

		final JTextField textField = new JTextField();
		textField.setBounds(160, 50, 190, 25);
		panel.add(textField);

		final JButton button = new JButton();
		button.setText("提交");
		button.setBounds(390, 50, 60, 25);
		panel.add(button);

		ActionListener actionListener = new ActionListener() {

			public void actionPerformed(ActionEvent e) {

				String borrowID = textField.getText();

				JOptionPane.showMessageDialog(null, borrowManager
						.deleteBorrow(borrowID));

				textField.setText(null);
			}

		};

		button.addActionListener(actionListener);

		frame.setContentPane(panel);
		frame.validate();

	}

	// 查找借书记录
	public void searchByBorrowID() throws Exception {

		final JPanel panel = new JPanel();
		panel.setLayout(null);
		panel.setBounds(0, 0, 490, 347);
		frame.add(panel);

		final JLabel label = new JLabel();
		label.setText("借书编号");
		label.setBounds(70, 50, 95, 25);
		panel.add(label);

		final JTextField textField = new JTextField();
		textField.setBounds(160, 50, 190, 25);
		panel.add(textField);

		final JButton button = new JButton();
		button.setText("提交");
		button.setBounds(390, 50, 60, 25);
		panel.add(button);

		final JScrollPane scrollPane = new JScrollPane();
		panel.add(scrollPane);
		scrollPane.setBounds(5, 90, 480, 200);

		final JTable table = new JTable();
		scrollPane.setViewportView(table);

		ActionListener actionListener = new ActionListener() {

			public void actionPerformed(ActionEvent e) {

				String borrowID = textField.getText();

				Vector rowData = new Vector();
				Vector row = new Vector();
				Vector columnNames = new Vector();
				Borrow borrow = borrowManager.searchByID(borrowID);
				if (borrow == null) {

					columnNames.add("没有借书");

				} else {
					row.add(borrow.getBorrowID());
					row.add(borrow.getBook().getBookId());
					row.add(borrow.getBook().getBookName());
					row.add(borrow.getBook().getAuthor());
					row.add(borrow.getUser().getUserId());
					row.add(borrow.getUser().getUserName());

					columnNames.add("编号");
					columnNames.add("书编号");
					columnNames.add("书名");
					columnNames.add("作者");
					columnNames.add("用户编号");
					columnNames.add("用户");
				}
				rowData.add(row);

				JTable table = new JTable(rowData, columnNames);
				JScrollPane jpanel = new JScrollPane(table);
				jpanel.setBounds(5, 90, 480, 200);
				panel.add(jpanel);
				textField.setText(null);
			}

		};

		button.addActionListener(actionListener);

		frame.setContentPane(panel);
		frame.validate();
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -