Java 编写航班查询系统 窗体程序 完整源码

开发环境

开发语言为Java,开发环境Eclipse或者IDEA都可以。数据库采用:MySQL。运行主程序,或者执行打开JAR文件即可以运行本程序。

系统框架

利用JDK自带的SWING框架开发,需要导入MySMyQL的JDBCJAR包。MySQL数据库,纯窗体模式,直接运行Main文件即可以。同时带有详细得设计文档

系统主要功能

航班查询系统系统用Java语言编写,是一个简单的窗体程序,采用swing框架编写,系统涉及到文件、UI、数据库操作、事件等操作。通过运行Main.java,或者直接运行解压文件假下的JAR文件

操作说明:

整个航班查询系统采用的图形化界面方式进行设计,最上面是菜单栏,下面是快捷工具栏

1 航班信息维护。包括航班的新增,航班的修改、航班的删除。航班信息包括:航班号、是否满仓、起飞时间、落地时间、票价、折扣

2 航班信息查询:包括航班号来查询航班信息,根据起始城市来查询

3 通过快捷图标来执行相关操作

4 更换系统背景图片

实现的主要效果

关键代码

import java.awt.*;
import java.awt.event.*;
import java.util.prefs.*;
import javax.swing.*;

/**
 * 这个类定义了程序的主界面. 包括菜单, 工具栏, 主功能操作按钮, 显示界面等.
 * @author wenwen
 */
public class MainFrame extends JFrame
{
    public MainFrame()
    {
        /*
         * 读入用户对程序界面进行配置的参数. 
         */
        Preferences root = Preferences.userRoot();
        userPrefs = root.node("/net/sfte/jk88811");
        
        setTitle("航班管理信息系统 " + FlightMIS.getVersion());
        
        //设置窗口大小与上次系统关闭时一样.
        Toolkit kit = Toolkit.getDefaultToolkit();
        Dimension screenSize = kit.getScreenSize();
        int defaultWidth = screenSize.width;
        int defaultHeight = screenSize.height;
        int topLeftX = userPrefs.getInt("topLeftX", 0);
        int topLeftY = userPrefs.getInt("topLeftY", 0);
        int width = userPrefs.getInt("width", defaultWidth);
        int height = userPrefs.getInt("height", defaultHeight);
        //如果窗口大小与显示屏大小基本相等, 则最大化窗口.
        if (Math.abs(width - defaultWidth) <= 30 &&
            Math.abs(height - defaultHeight) <= 30)
        {
            setBounds(defaultWidth / 10, defaultHeight / 10, 
                (int) (defaultWidth / 1.2), (int) (defaultHeight / 1.2));
            setExtendedState(MAXIMIZED_BOTH);
        }
        else
        {
            setBounds(topLeftX, topLeftY, width, height);
        }
        
        //设置窗口小图标
        Image img = kit.getImage(getClass().getResource("images/icon.png"));
        setIconImage(img);
        
        //中部主面板, 显示图片.
        String imageName = userPrefs.get("backgroundImage", "images/plane.jpg");
        mainPanel = new MainPanel(imageName);
        add(mainPanel, BorderLayout.CENTER);
        
        /*
         * 创建事件监听动作Action
         */
        actionExit = new ExitAction();
        actionAbout = new AboutAction(this);
        actionInput = new InputAction(mainPanel);
        actionLoadIn = new LoadInAction(this);
        actionModify = new ModifyAction(mainPanel);
        actionDelete = new DeleteAction(mainPanel);
        actionQueryWithId = new QueryWithIdAction(mainPanel);
        actionQueryWithCity = new QueryWithCityAction(mainPanel);
        actionChangeBackground = new ChangeBackgroundAction(this, mainPanel);
        
        /*
         * 主菜单设置
         */
        JMenuBar menuBar = new JMenuBar();
        setJMenuBar(menuBar);
        
        //文件菜单
        JMenu fileMenu = new JMenu("文件(F)");
        fileMenu.setMnemonic('F');
        menuBar.add(fileMenu);
        
        //unfinished
        JMenuItem systemItem = new JMenuItem("系统设置");
        systemItem.setAccelerator(KeyStroke.getKeyStroke(
            KeyEvent.VK_S, InputEvent.CTRL_MASK));
        fileMenu.add(systemItem);
        
        JMenuItem changeImageItem = new JMenuItem(actionChangeBackground);
        fileMenu.add(changeImageItem);
        
        fileMenu.addSeparator();
        
        //退出系统.
        JMenuItem exitItem = new JMenuItem(actionExit);
        exitItem.setAccelerator(KeyStroke.getKeyStroke(
            KeyEvent.VK_X, InputEvent.CTRL_MASK));
        fileMenu.add(exitItem);
        
        //操作菜单
        JMenu operationMenu = new JMenu("操作(O)");
        operationMenu.setMnemonic('O');
        menuBar.add(operationMenu);
        
        JMenu addFlightMenu = new JMenu("新增航班信息");
        operationMenu.add(addFlightMenu);
        
        JMenuItem addItem = new JMenuItem(actionInput);
        addItem.setAccelerator(KeyStroke.getKeyStroke(
            KeyEvent.VK_I, InputEvent.CTRL_MASK));
        addFlightMenu.add(addItem);
        
        JMenuItem loadInItem = new JMenuItem(actionLoadIn);
        loadInItem.setAccelerator(KeyStroke.getKeyStroke(
            KeyEvent.VK_L, InputEvent.CTRL_MASK));
        addFlightMenu.add(loadInItem);
        
        operationMenu.addSeparator();
        
        JMenu queryMenu = new JMenu("查询航班信息");
        operationMenu.add(queryMenu);
        
        JMenuItem queryWithIdItem = new JMenuItem(actionQueryWithId);
        queryWithIdItem.setAccelerator(KeyStroke.getKeyStroke(
            KeyEvent.VK_Q, InputEvent.CTRL_MASK));
        queryMenu.add(queryWithIdItem);
        
        JMenuItem queryWithCityItem = new JMenuItem(actionQueryWithCity);
        queryWithCityItem.setAccelerator(KeyStroke.getKeyStroke(
            KeyEvent.VK_C, InputEvent.CTRL_MASK));
        queryMenu.add(queryWithCityItem);
        
        operationMenu.addSeparator();
        
        JMenuItem modifyItem = new JMenuItem(actionModify);
        modifyItem.setAccelerator(KeyStroke.getKeyStroke(
            KeyEvent.VK_M, InputEvent.CTRL_MASK));
        operationMenu.add(modifyItem);
        
        JMenuItem deleteItem = new JMenuItem(actionDelete);
        deleteItem.setAccelerator(KeyStroke.getKeyStroke(
            KeyEvent.VK_D, InputEvent.CTRL_MASK));
        operationMenu.add(deleteItem);
        
        //查看菜单
        JMenu viewMenu = new JMenu("查看(V)");
        viewMenu.setMnemonic('V');
        menuBar.add(viewMenu);
        
        JMenu lookAndFeelMenu = new JMenu("外观");
        viewMenu.add(lookAndFeelMenu);
        //外观单选菜单项所属的组
        group = new ButtonGroup();
        //设置程序外观(Look And Feel)
        String defaultLookAndFeel = userPrefs.get("lookAndFeel", 
            UIManager.getCrossPlatformLookAndFeelClassName());
        try
        {
            UIManager.setLookAndFeel(defaultLookAndFeel);
            SwingUtilities.updateComponentTreeUI(MainFrame.this);
        }
        catch (Exception e)
        {
            //do nothing
        }
        UIManager.LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
        for (UIManager.LookAndFeelInfo info : infos)
        {
            addLookAndFeelMenuItem(lookAndFeelMenu, info.getName(),
                info.getClassName(), defaultLookAndFeel);
        }
        
        viewMenu.addSeparator();
        
        //状态栏
        statusBar = new StatusBar();
        add(statusBar, BorderLayout.SOUTH);
        boolean displayStatusBar = userPrefs.getBoolean("displayStatusBar", true);
        statusBar.setVisible(displayStatusBar);
        //控制是否显示状态栏的菜单项
        final JCheckBoxMenuItem statusBarItem = new JCheckBoxMenuItem("状态栏");
        statusBarItem.setSelected(displayStatusBar);
        statusBarItem.addActionListener(new
            ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    boolean sign = statusBarItem.isSelected();
                    statusBar.setVisible(sign);
                    validate();
                    userPrefs.putBoolean("displayStatusBar", sign);
                }
            });
        viewMenu.add(statusBarItem);
        
        //帮助菜单
        JMenu helpMenu = new JMenu("帮助(H)");
        helpMenu.setMnemonic('H');
        menuBar.add(helpMenu);
        
        //unfinished
        JMenuItem helpItem = new JMenuItem("系统帮助");
        helpItem.setAccelerator(KeyStroke.getKeyStroke(
            KeyEvent.VK_H, InputEvent.CTRL_MASK));
        //helpItem.addActionListener();
        helpMenu.add(helpItem);
        
        //unfinished.
        JMenuItem newVersionItem = new JMenuItem("检查新版本");
        //newVersionItem.addActionListener();
        helpMenu.add(newVersionItem);
        
        helpMenu.addSeparator();
        
        JMenuItem aboutItem = new JMenuItem(actionAbout);
        aboutItem.setAccelerator(KeyStroke.getKeyStroke(
            KeyEvent.VK_A, InputEvent.CTRL_MASK));
        helpMenu.add(aboutItem);
        
        //创建工具栏.
        toolBar = new JToolBar("工具栏");
        toolBar.setFloatable(false);
        toolBar.setRollover(true);
        add(toolBar, BorderLayout.NORTH);
        //控制是否显示工具栏.
        boolean displayToolBar = userPrefs.getBoolean("displayToolBar", true);
        toolBar.setVisible(displayToolBar);
        final JCheckBoxMenuItem toolBarItem = new JCheckBoxMenuItem("工具栏");
        viewMenu.add(toolBarItem);
        toolBarItem.setSelected(displayToolBar);
        toolBarItem.addActionListener(new
            ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    boolean sign = toolBarItem.isSelected();
                    toolBar.setVisible(sign);
                    validate();
                    userPrefs.putBoolean("displayToolBar", sign);
                }
            });
        
        toolBar.add(createButton(actionLoadIn, "images/loadIn.png", "导入航班信息"));
        toolBar.add(createButton(actionInput, "images/input.png", "录入航班信息"));
        toolBar.addSeparator();
        toolBar.add(createButton(actionQueryWithId, "images/queryWithId.png", "按航班号查询"));
        toolBar.add(createButton(actionQueryWithCity, "images/queryWithCity.png", "按起飞抵达城市查询"));
        toolBar.addSeparator();
        toolBar.add(createButton(actionModify, "images/modify.png", "修改航班信息"));
        toolBar.add(createButton(actionDelete, "images/delete.png", "删除航班信息"));
        toolBar.addSeparator();
        toolBar.add(createButton(actionAbout, "images/about.png", "关于"));
        toolBar.add(createButton(actionExit, "images/exit.png", "退出系统"));
        
        //注册窗口关闭监听器
        addWindowListener(new
            WindowAdapter()
            {
                public void windowClosing(WindowEvent e)
                {
                    exitSystem();
                }
            });
        
        //设置弹出菜单
        createPopupMenu();
    }
    
    /**
     * 为每一种外观创建一个菜单项, 并安装相应的事件监听器
     * @author wenwen
     */
    public void addLookAndFeelMenuItem(JMenu menu, String name, 
        final String plafName, String defaultLookAndFeel)
    {
        final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(name);
        if (plafName.equals(defaultLookAndFeel))
            menuItem.setSelected(true);
        menuItem.addActionListener(new
            ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    if (menuItem.isSelected())
                    {
                        //将用户选择的外观保存到用户参数中, 以便下次启动时使用默认外观.
                        userPrefs.put("lookAndFeel", plafName);
                        //动态设置与菜单项对应的外观
                        try
                        {
                            UIManager.setLookAndFeel(plafName);
                            SwingUtilities.updateComponentTreeUI(MainFrame.this);
                            MainFrame.this.remove(popupMenu);
                            createPopupMenu();
                        }
                        catch (Exception ex)
                        {
                            // do nothing.
                        }
                    }
                }
            });
        group.add(menuItem);
        menu.add(menuItem);
    }
    /**
     * 系统关闭时调用该方法, 保存系统参数以及尚未保存的航班信息资料.
     * @author wenwen
     */
    public void exitSystem()
    {
        int result = JOptionPane.showConfirmDialog(MainFrame.this,
            "您确定要退出本航班信息管理系统吗?", "程序退出确认",
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (result != JOptionPane.YES_OPTION)
            return ;
        //保存窗口位置参数, 以便下次启动时使用.
        userPrefs.putInt("topLeftX", getX());
        userPrefs.putInt("topLeftY", getY());
        userPrefs.putInt("width", getWidth());
        userPrefs.putInt("height", getHeight());
        
        //保存背景图片完整路径, 以便下次启动时载入.
        String imageName = mainPanel.getBackgroundImageName();
        userPrefs.put("backgroundImage", imageName);
        System.exit(0);
    }
    /**
     * 为工具栏创建按键
     * @author wenwen
     */
    public JButton createButton(Action action, String imageName, String toolTip)
    {
        JButton b = new JButton(new ImageIcon(
            getClass().getResource(imageName)));
        b.setToolTipText(toolTip);
        b.addActionListener(action);
        return b;
    }
    /**
     * 创建弹出式菜单
     * @author wenwen
     */
    private void createPopupMenu()
    {
        popupMenu = new JPopupMenu();
        popupMenu.add(new JMenuItem(actionInput));
        popupMenu.add(new JMenuItem(actionLoadIn));
        popupMenu.addSeparator();
        popupMenu.add(new JMenuItem(actionQueryWithId));
        popupMenu.add(new JMenuItem(actionQueryWithCity));
        popupMenu.addSeparator();
        popupMenu.add(new JMenuItem(actionModify));
        popupMenu.add(new JMenuItem(actionDelete));
        popupMenu.addSeparator();
        popupMenu.add(new JMenuItem(actionChangeBackground));
        
        //将右键菜单添加到mainPanel上
        mainPanel.setComponentPopupMenu(popupMenu);
        //下面这条语句是必须的, 这是Java本身的一个bug. 请查看Java bug 4966109
        mainPanel.addMouseListener(new MouseAdapter() {    });
    }
    /**
     * 系统退出事件处理.
     * @author wenwen
     */
    private class ExitAction extends AbstractAction
    {
        public ExitAction()
        {
            putValue(Action.NAME, "退出");
            putValue(Action.SHORT_DESCRIPTION, "退出系统");
        }
        public void actionPerformed(ActionEvent e)
        {
            exitSystem();
        }
    }
    
    //外观菜单所属的单选按钮组.
    private ButtonGroup group;
    //程序界面配置的用户参数.
    private final Preferences userPrefs;
    private StatusBar statusBar;
    private JToolBar toolBar;
    private MainPanel mainPanel;
    private JPopupMenu popupMenu;
    
    //事件监听动作Action.
    private ExitAction actionExit;
    private AboutAction actionAbout;
    private InputAction actionInput;
    private LoadInAction actionLoadIn;
    private ModifyAction actionModify;
    private DeleteAction actionDelete;
    private QueryWithIdAction actionQueryWithId;
    private QueryWithCityAction actionQueryWithCity;
    private ChangeBackgroundAction actionChangeBackground;
}

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
# OOP(机试) 本程序总结文章:http://blog.qiji.tech/?p=10344 - - - ## 程序基本要求 一、项目名称: Air Infomation Programming 基于控制台的航班信息程序,简称AIP 二、具体要求如下: (1)显示航班信息程序主菜单,如图-1所示,包括: * 1)列出所有航班 * 2)按起飞时间查询 * 3)按目的地查询 * 4)删除航班 * 5)更新航班 * 6)退出系统 (2)列出所有航班:查出所有航班的信息,以列表形式显示,包括:编号,航班号,目的地,起飞日期。 (3)按起飞时间查询:输入起飞时间(格式如2011-2-25),查出所有这一天的航班。 (4)按目的地查询:输入目的地,查出所有飞往此地的航班。 (5)删除航班:删除指定编号的航班。 (6)更新航班:更新指定编号的航班。 (7)退出系统。 三、类的设计 需要定义如下类 * 航班信息实体类(AirInfo) * 航班编号(id) * 航班号(flight_number) * 目的地(destination) * 起飞日期(flight_date) * 航班信息管理类AirInfoManager类 * 程序入口类TestAirInfo类 四、具体要求及推荐实现步骤 1. 创建实体类AirInfo,属性私有化,根据业务提供需要的构造方法和setter/getter方法。 1. 创建航班管理AirInfoManager类,在类中提供列出所有航班的方法,按起飞时间查询的方法、按目的地查询的方法、删除航班的方法、更新航班的方法、退出程序的方法。 2. 创建TestAirInfo类,启动和运行程序。 3. 航班的信息用ArrayList(或数组)保存。 4. 要求代码规范,命名正确。 - - -

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

计算机程序

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值