使用 Swing 组件库用Java写一个gui能够实现对停车位的信息管理(车位号、车主姓名、性别、年龄、 车牌号),要代码不用解释过程
时间: 2023-02-09 14:56:03 浏览: 164
基于Java的停车场管理系统(车牌识别)
5星 · 资源好评率100%
这是一份使用 Swing 组件库在 Java 中创建 GUI 来管理停车位信息(车位号、车主姓名、性别、年龄、车牌号)的代码:
```
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class ParkingInfoManager {
private JFrame mainFrame;
private JLabel headerLabel;
private JLabel statusLabel;
private JPanel controlPanel;
private JLabel msglabel;
public ParkingInfoManager() {
prepareGUI();
}
public static void main(String[] args) {
ParkingInfoManager swingControlDemo = new ParkingInfoManager();
swingControlDemo.showTextFieldDemo();
}
private void prepareGUI() {
mainFrame = new JFrame("停车位信息管理");
mainFrame.setSize(400, 400);
mainFrame.setLayout(new GridLayout(3, 1));
headerLabel = new JLabel("", JLabel.CENTER);
statusLabel = new JLabel("", JLabel.CENTER);
statusLabel.setSize(350, 100);
mainFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent) {
System.exit(0);
}
});
controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
mainFrame.add(headerLabel);
mainFrame.add(controlPanel);
mainFrame.add(statusLabel);
mainFrame.setVisible(true);
}
private void showTextFieldDemo() {
headerLabel.setText("停车位信息录入");
JLabel parkingNumLabel = new JLabel("车位号:", JLabel.RIGHT);
JLabel ownerNameLabel = new JLabel("车主姓名:", JLabel.RIGHT);
JLabel genderLabel = new JLabel("性别:", JLabel.RIGHT);
JLabel ageLabel = new JLabel("年龄:", JLabel.RIGHT);
JLabel carPlateLabel = new JLabel("车牌号:", JLabel.RIGHT);
final JTextField parkingNumText = new JTextField(6);
final JTextField ownerNameText = new JTextField(6);
final JTextField genderText = new JTextField(6);
final JTextField ageText = new JTextField
阅读全文