2025.3.26(周三)

航空公司查询代码:

package air;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Air {
    public static void main(String[] args) {
        // 创建主窗口
        JFrame frame = new JFrame("航空服务查询系统");
        frame.setSize(500, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout(null);

        // 创建航线选择标签和下拉框
        JLabel labelRoute = new JLabel("请选择您的航线:");
        labelRoute.setBounds(50, 30, 150, 25);
        frame.add(labelRoute);

        String[] routes = {"请选择", "欧美", "国外非欧美", "国内"};
        JComboBox<String> comboRoute = new JComboBox<>(routes);
        comboRoute.setBounds(200, 30, 200, 25);
        frame.add(comboRoute);

        // 创建舱位选择标签和下拉框
        JLabel labelClass = new JLabel("请选择您的舱位:");
        labelClass.setBounds(50, 70, 150, 25);
        frame.add(labelClass);

        String[] classes = {"请选择", "商务舱", "经济舱"};
        JComboBox<String> comboClass = new JComboBox<>(classes);
        comboClass.setBounds(200, 70, 200, 25);
        frame.add(comboClass);

        // 创建飞行时间选择标签和下拉框
        JLabel labelTime = new JLabel("请选择您的飞行时间:");
        labelTime.setBounds(50, 110, 150, 25);
        frame.add(labelTime);

        String[] times = {"请选择", "两小时以内", "超过两小时"};
        JComboBox<String> comboTime = new JComboBox<>(times);
        comboTime.setBounds(200, 110, 200, 25);
        frame.add(comboTime);

        // 结果显示标签
        JLabel resultLabel = new JLabel("");
        resultLabel.setBounds(50, 200, 400, 25);
        frame.add(resultLabel);

        // 创建按钮
        JButton button = new JButton("查询服务");
        button.setBounds(150, 150, 120, 30);
        frame.add(button);

        // 按钮点击事件
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int button1 = comboRoute.getSelectedIndex();
                int button2 = comboClass.getSelectedIndex();
                int button3 = comboTime.getSelectedIndex();

                if (button1 == 0 || button2 == 0 || button3 == 0) {
                    resultLabel.setText("❌ 请选择所有选项!");
                    return;
                }

                String service = query(button1, button2, button3);
                resultLabel.setText("✅ " + service);
            }
        });

        // 显示窗口
        frame.setVisible(true);
    }

    // 查询服务
    public static String query(int b1, int b2, int b3) {
        if (b1 == 1) {
            return "享受服务:食物供应、播放电影";
        }
        if (b1 == 2 && b2 == 1) {
            return "享受服务:食物供应、播放电影";
        }
        if (b1 == 2 && b2 == 2) {
            return "享受服务:食物供应";
        }
        if (b1 == 3 && b2 == 1) {
            return "享受服务:食物供应";
        }
        if (b1 == 3 && b2 == 2 && b3 == 2) {
            return "享受服务:食物供应";
        }
        return "享受服务:无";
    }
}

 

posted @ 2025-03-23 09:35  记得关月亮  阅读(4)  评论(0)    收藏  举报