Java 羽毛球场地预约系统gui界面包含从8:00-20:00的时间,室内室外选择,包含日期,预约键,10个场地按钮,取消预约按钮代码
时间: 2024-03-25 14:41:54 浏览: 137
国科大羽毛球场地一键查询
以下是一个简单的 Java GUI 羽毛球场地预约系统界面,包含从8:00-20:00的时间,室内室外选择,包含日期,预约键,10个场地按钮,以及取消预约按钮的代码:
```java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class BadmintonReservationSystem extends JFrame implements ActionListener {
private JLabel titleLabel, dateLabel, timeLabel, typeLabel, courtLabel;
private JTextField dateTextField;
private JButton reserveButton, cancelButton;
private JRadioButton indoorRadioButton, outdoorRadioButton;
private ButtonGroup typeButtonGroup;
private JButton[] courtButtons;
private int selectedCourt = -1;
public BadmintonReservationSystem() {
// Set up the GUI components
titleLabel = new JLabel("Badminton Court Reservation System");
titleLabel.setFont(new Font("Arial", Font.BOLD, 20));
titleLabel.setHorizontalAlignment(JLabel.CENTER);
dateLabel = new JLabel("Date:");
dateTextField = new JTextField(10);
timeLabel = new JLabel("Time:");
JPanel timePanel = new JPanel(new GridLayout(2, 6));
for (int i = 8; i <= 20; i++) {
timePanel.add(new JLabel(i + ":00"));
}
typeLabel = new JLabel("Type:");
indoorRadioButton = new JRadioButton("Indoor", true);
outdoorRadioButton = new JRadioButton("Outdoor");
typeButtonGroup = new ButtonGroup();
typeButtonGroup.add(indoorRadioButton);
typeButtonGroup.add(outdoorRadioButton);
courtLabel = new JLabel("Court:");
courtButtons = new JButton[10];
for (int i = 0; i < 10; i++) {
courtButtons[i] = new JButton("Court " + (i + 1));
courtButtons[i].addActionListener(this);
}
reserveButton = new JButton("Reserve");
reserveButton.addActionListener(this);
cancelButton = new JButton("Cancel Reservation");
cancelButton.addActionListener(this);
// Add the components to the JFrame
JPanel mainPanel = new JPanel(new GridLayout(6, 1));
mainPanel.add(titleLabel);
JPanel datePanel = new JPanel(new FlowLayout());
datePanel.add(dateLabel);
datePanel.add(dateTextField);
mainPanel.add(datePanel);
mainPanel.add(timeLabel);
mainPanel.add(timePanel);
JPanel typePanel = new JPanel(new FlowLayout());
typePanel.add(typeLabel);
typePanel.add(indoorRadioButton);
typePanel.add(outdoorRadioButton);
mainPanel.add(typePanel);
JPanel courtPanel = new JPanel(new FlowLayout());
courtPanel.add(courtLabel);
for (int i = 0; i < 10; i++) {
courtPanel.add(courtButtons[i]);
}
mainPanel.add(courtPanel);
JPanel buttonPanel = new JPanel(new FlowLayout());
buttonPanel.add(reserveButton);
buttonPanel.add(cancelButton);
mainPanel.add(buttonPanel);
add(mainPanel);
// Set up the JFrame
setTitle("Badminton Court Reservation System");
setSize(600, 400);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == reserveButton) {
String date = dateTextField.getText();
String time = null;
for (int i = 8; i <= 20; i++) {
if (courtButtons[i - 8].isEnabled()) {
time = i + ":00";
}
}
String type = indoorRadioButton.isSelected() ? "Indoor" : "Outdoor";
String court = "Court " + (selectedCourt + 1);
if (date != null && time != null && type != null && court != null) {
JOptionPane.showMessageDialog(null, "Reservation successful!");
} else {
JOptionPane.showMessageDialog(null, "Please select a court.");
}
} else if (e.getSource() == cancelButton) {
for (int i = 0; i < 10; i++) {
courtButtons[i].setEnabled(true);
}
selectedCourt = -1;
} else {
for (int i = 0; i < 10; i++) {
if (e.getSource() == courtButtons[i]) {
selectedCourt = i;
courtButtons[i].setEnabled(false);
} else {
courtButtons[i].setEnabled(true);
}
}
}
}
public static void main(String[] args) {
new BadmintonReservationSystem();
}
}
```
注意:这只是一个简单的实现,你需要根据你的项目需求进行修改和完善。
阅读全文