Java 羽毛球场地预约系统gui界面包含一个场地表格(一共分为室内10个和室外5个),预约按钮,取消预约按钮,室内室外选择按钮,时间段和日期代码
时间: 2024-03-29 12:36:10 浏览: 97
以下是一个简单的 Java 羽毛球场地预约系统 GUI 界面的代码,包含了场地表格、预约按钮、取消预约按钮、室内室外选择按钮、时间段和日期代码:
```java
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
public class BadmintonBookingSystemGUI extends JFrame {
private JTable courtTable;
private JButton bookButton, cancelButton;
private JRadioButton indoorButton, outdoorButton;
private JComboBox<String> timeComboBox, dateComboBox;
public BadmintonBookingSystemGUI() {
super("Badminton Booking System");
// Create table model and set up court table
DefaultTableModel model = new DefaultTableModel(new Object[]{"Court No.", "Status"}, 0);
model.addRow(new Object[]{"Indoor Court 1", "Available"});
model.addRow(new Object[]{"Indoor Court 2", "Available"});
// ... add more rows for indoor and outdoor courts
courtTable = new JTable(model);
// Set up booking and cancel buttons
bookButton = new JButton("Book");
cancelButton = new JButton("Cancel");
// Set up indoor and outdoor radio buttons
indoorButton = new JRadioButton("Indoor");
outdoorButton = new JRadioButton("Outdoor");
ButtonGroup group = new ButtonGroup();
group.add(indoorButton);
group.add(outdoorButton);
// Set up time and date combo boxes
String[] times = new String[]{"09:00-10:00", "10:00-11:00", "11:00-12:00", "13:00-14:00", "14:00-15:00", "15:00-16:00"};
timeComboBox = new JComboBox<>(times);
String[] dates = new String[]{"2022-01-01", "2022-01-02", "2022-01-03", "2022-01-04", "2022-01-05"};
dateComboBox = new JComboBox<>(dates);
// Set up layout
JPanel panel = new JPanel(new BorderLayout());
JPanel buttonPanel = new JPanel(new GridLayout(1, 2));
buttonPanel.add(bookButton);
buttonPanel.add(cancelButton);
JPanel radioPanel = new JPanel(new GridLayout(1, 2));
radioPanel.add(indoorButton);
radioPanel.add(outdoorButton);
JPanel comboPanel = new JPanel(new FlowLayout());
comboPanel.add(new JLabel("Time: "));
comboPanel.add(timeComboBox);
comboPanel.add(new JLabel("Date: "));
comboPanel.add(dateComboBox);
panel.add(new JScrollPane(courtTable), BorderLayout.CENTER);
panel.add(buttonPanel, BorderLayout.SOUTH);
panel.add(radioPanel, BorderLayout.NORTH);
panel.add(comboPanel, BorderLayout.SOUTH);
add(panel);
// Set up frame
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(800, 600);
setVisible(true);
}
public static void main(String[] args) {
new BadmintonBookingSystemGUI();
}
}
```
这个代码创建了一个 BadmintonBookingSystemGUI 类,继承了 JFrame 类,实现了一个简单的羽毛球场地预约系统的 GUI 界面。界面包含了一个场地表格,预约按钮,取消预约按钮,室内室外选择按钮,时间段和日期选择框。用户可以在表格中选择一个场地,选择时间和日期,然后点击预约或取消预约按钮来进行预约或取消预约操作。
阅读全文