航班信息的查询与检索Java,航班信息查询与检索(java)

大二上时用C语言写过一个关于航班信息查询与检索的课程设计,当时是自己抄代码,然后再让学长帮改的,前天晚上在“抄”代码时,突然想用java把那个课设题再写一次,于是昨天晚上就开始了,当然还是先在网上找了不少“成品”做参考,半借鉴,半修改,马马虎虎写了一个功能比较少的版本,以后再写更高版本的。

这个小程序的代码分为四个模块:主框架(MainWindow),关于飞机航班号、起飞(目的)城市与起飞时间(Plane),对航班信息的添加查询等操作(FlightInfoOperation),以及对文件的处理(IOOperation)。

主窗口图:

2496ae813c8a52986118a1db9395205a.png

添加窗口图:

5162e36c21900241fd99edd0e29881de.png

查询窗口图:

(其中可以通过航班号、起飞城市任意一个查询或两者查询)

511e7d818c71d2fa1c7c9305666398e7.png

下面给出这个代码的部分代码:

FlightInfoOperation里的

public FlightInfoOperation() {

mainFrame = new Frame("航班信息查询与检索");

mainFrame.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

mainFrame.setSize(WIDTH, HEIGHT);

mainFrame.setVisible(true);

Dimension frameSize = mainFrame.getSize();

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

mainFrame.setLocation((screenSize.width - frameSize.width) / 2,

(screenSize.height - frameSize.height) / 2);

buttonPanel = new Panel();

mainFrame.add(buttonPanel, BorderLayout.NORTH);

addButton = new Button("Add");

addButton.addActionListener(this);

searchButton = new Button("Search");

searchButton.addActionListener(this);

exitButton = new Button("Exit");

exitButton.addActionListener(this);

aboutButton = new Button("About");

aboutButton.addActionListener(this);

planeInfo = new TextArea();

planeInfo.setFont(new Font("serif", Font.PLAIN, 18));

buttonPanel.add(addButton);

buttonPanel.add(searchButton);

buttonPanel.add(exitButton);

buttonPanel.add(aboutButton);

mainFrame.add(planeInfo);

/**

* 添加飞机信息的窗口设置

*/

addFrame = new Frame();

addFrame.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

addFrame.setVisible(false);

}

});

inputLabPanel = new Panel(new GridLayout(4, 2));

inputBtnPanel = new Panel();

String[] inputLbName = { "airNum:", "StartCity:", "Destination:",

"FlightTime" };

String[] inputBtnName = { "Save", "Delete", "Quit" };

// Add窗口中各字段名称、按钮设置

for (int i = 0; i < 4; i++) {

inputLab[i] = new Label(inputLbName[i]);

inputTf[i] = new TextField(15);

inputLabPanel.add(inputLab[i]);

inputLabPanel.add(inputTf[i]);

}

for (int i = 0; i < 3; i++) {

inputBtn[i] = new Button(inputBtnName[i]);

inputBtn[i].addActionListener(this);

inputBtnPanel.add(inputBtn[i]);

}

inputBtn[2].setActionCommand("add");// 用来获取对象的标签或事先为这个对象设置的命令名

addFrame.add(inputLabPanel, BorderLayout.CENTER);

addFrame.add(inputBtnPanel, BorderLayout.SOUTH);

addFrame.pack();

addFrame.setLocationRelativeTo(mainFrame);

/**

* set searchFrame which is used to search plane information

*/

searchFrame = new Frame("Search plane");

searchFrame.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

searchFrame.setVisible(false);

}

});

schLabPanel = new Panel(new GridLayout(2, 2));

schBtnPanel = new Panel();

String schLabName[] = { "airNum :", "StartCity :" };

String schBtnName[] = { "Ok", "Quit" };

for (int i = 0; i < 2; i++) {

schLab[i] = new Label(schLabName[i]);

schTf[i] = new TextField(15);

schLabPanel.add(schLab[i]);

schLabPanel.add(schTf[i]);

}

for (int i = 0; i < 2; i++) {

schBtn[i] = new Button(schBtnName[i]);

schBtn[i].addActionListener(this);

schBtnPanel.add(schBtn[i]);

}

schBtn[1].setActionCommand("search");

searchFrame.add(schLabPanel, BorderLayout.CENTER);

searchFrame.add(schBtnPanel, BorderLayout.SOUTH);

searchFrame.pack();

searchFrame.setLocationRelativeTo(mainFrame);

/**

* IO operation object

*/

ioo = new IOOperation();

plane = ioo.getAllPlane();

}

文件操作部分

public class IOOperation {

private File file = new File("E:\\wenjianyuan\\info");

public IOOperation() {

try {

if (!file.exists()) {

file.createNewFile();

}

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

/**

* write to file

*/

public void write(Plane[] wPlane) {

try {

FileOutputStream fos = new FileOutputStream(file);

ObjectOutputStream objOut = new ObjectOutputStream(fos);

objOut.writeObject(wPlane);

objOut.close();

fos.close();

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

/**

* read all informations from the file

*/

public Plane[] getAllPlane() {

Plane[] plane = new Plane[100];

try {

if (file.length() > 0) {

FileInputStream fis = new FileInputStream(file);

ObjectInputStream ois=new ObjectInputStream(fis);

plane= (Plane[]) ois.readObject();

ois.close();

fis.close();

}

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return plane;

}

}

感兴趣的朋友可以到:http://download.csdn.net/detail/yanghai0321/4185470 下载完整代码。

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 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
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值