图书管理系统javaGui代码
时间: 2024-04-14 19:22:02 浏览: 101
基于java的图书管理系统源代码.pdf
很抱歉,根据提供的引用内容,没有提供具体的Java GUI图书管理系统的代码。但是,我可以为您提供一个简单的Java GUI图书管理系统的代码示例,供您参考:
```java
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class BookManagementSystem extends JFrame {
private JTextField bookNameField;
private JTextField authorField;
private JTextField publisherField;
private JButton addButton;
private JTextArea bookListArea;
public BookManagementSystem() {
setTitle("图书管理系统");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
JPanel inputPanel = new JPanel();
inputPanel.setLayout(new GridLayout(3, 2));
inputPanel.add(new JLabel("书名:"));
bookNameField = new JTextField();
inputPanel.add(bookNameField);
inputPanel.add(new JLabel("作者:"));
authorField = new JTextField();
inputPanel.add(authorField);
inputPanel.add(new JLabel("出版社:"));
publisherField = new JTextField();
inputPanel.add(publisherField);
addButton = new JButton("添加");
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String bookName = bookNameField.getText();
String author = authorField.getText();
String publisher = publisherField.getText();
String bookInfo = "书名:" + bookName + " 作者:" + author + " 出版社:" + publisher + "\n";
bookListArea.append(bookInfo);
bookNameField.setText("");
authorField.setText("");
publisherField.setText("");
}
});
bookListArea = new JTextArea();
bookListArea.setEditable(false);
add(inputPanel, BorderLayout.NORTH);
add(addButton, BorderLayout.CENTER);
add(new JScrollPane(bookListArea), BorderLayout.SOUTH);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
BookManagementSystem bookManagementSystem = new BookManagementSystem();
bookManagementSystem.setVisible(true);
}
});
}
}
```
这是一个简单的图书管理系统的Java GUI代码示例。它包含一个窗口,用户可以输入书名、作者和出版社,并点击“添加”按钮将图书信息添加到图书列表中。图书列表以文本区域的形式显示在窗口的底部。
阅读全文