让图书管理系统运行时显示小窗口的代码
时间: 2023-09-11 18:07:00 浏览: 39
以下是使用Java Swing实现在运行图书管理系统时显示小窗口的示例代码:
```java
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
public class BookManagementSystem {
public static void main(String[] args) {
// 创建主窗口
JFrame mainFrame = new JFrame("图书管理系统");
mainFrame.setSize(800, 600);
mainFrame.setLocationRelativeTo(null);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 创建显示信息的标签
JLabel infoLabel = new JLabel("欢迎使用图书管理系统", SwingConstants.CENTER);
mainFrame.add(infoLabel);
// 创建小窗口
JFrame smallFrame = new JFrame("提示");
smallFrame.setSize(200, 100);
smallFrame.setLocationRelativeTo(mainFrame);
smallFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // 关闭小窗口时不关闭主窗口
// 创建小窗口中的标签
JLabel smallLabel = new JLabel("系统运行中...");
smallFrame.add(smallLabel);
// 显示主窗口和小窗口
mainFrame.setVisible(true);
smallFrame.setVisible(true);
}
}
```
在上述代码中,我们创建了一个主窗口`mainFrame`和一个小窗口`smallFrame`,并在`mainFrame`中添加了一个用于显示信息的标签`infoLabel`。在创建小窗口时,我们设置了它的位置相对于主窗口居中,并且在关闭小窗口时不关闭主窗口。最后,我们通过设置`setVisible(true)`来显示主窗口和小窗口。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)