用Java写一个弹出窗口的汽车管理系统
时间: 2023-06-20 19:10:24 浏览: 51
好的,下面是一个简单的汽车管理系统的Java代码,其中包含了一个弹出窗口:
```java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class CarManagementSystem extends JFrame implements ActionListener {
JLabel makeLabel, modelLabel, yearLabel, priceLabel;
JTextField makeField, modelField, yearField, priceField;
JButton addButton, deleteButton, clearButton, viewButton;
public CarManagementSystem() {
super("Car Management System");
makeLabel = new JLabel("Make:");
modelLabel = new JLabel("Model:");
yearLabel = new JLabel("Year:");
priceLabel = new JLabel("Price:");
makeField = new JTextField(20);
modelField = new JTextField(20);
yearField = new JTextField(20);
priceField = new JTextField(20);
addButton = new JButton("Add");
deleteButton = new JButton("Delete");
clearButton = new JButton("Clear");
viewButton = new JButton("View");
addButton.addActionListener(this);
deleteButton.addActionListener(this);
clearButton.addActionListener(this);
viewButton.addActionListener(this);
JPanel panel = new JPanel(new GridLayout(5, 2));
panel.add(makeLabel);
panel.add(makeField);
panel.add(modelLabel);
panel.add(modelField);
panel.add(yearLabel);
panel.add(yearField);
panel.add(priceLabel);
panel.add(priceField);
panel.add(addButton);
panel.add(deleteButton);
JPanel buttonPanel = new JPanel(new GridLayout(1, 3));
buttonPanel.add(clearButton);
buttonPanel.add(viewButton);
Container container = getContentPane();
container.add(panel, BorderLayout.NORTH);
container.add(buttonPanel, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == addButton) {
// add car to the system
} else if (e.getSource() == deleteButton) {
// delete car from the system
} else if (e.getSource() == clearButton) {
makeField.setText("");
modelField.setText("");
yearField.setText("");
priceField.setText("");
} else if (e.getSource() == viewButton) {
// view all cars in the system
}
}
public static void main(String[] args) {
CarManagementSystem cms = new CarManagementSystem();
cms.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
cms.setSize(400, 200);
cms.setVisible(true);
}
}
```
这个汽车管理系统包含了添加、删除、清空和查看所有车辆的功能。你可以根据需要进一步修改和完善它。