⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addflight.java

📁 航空售票系统的代码
💻 JAVA
字号:
package com.tarena.abs.server;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.io.*;import java.util.*;import com.tarena.abs.dao.*;import com.tarena.abs.model.*;public class AddFlight extends JDialog implements ActionListener{	private JLabel label0,label1,label2,label3,label4,label5,label6;	private JButton ok,cancel;	private JTextField t,t0,t1,t2,t3;	public AddFlight(JFrame frame){		super(frame,"添加航班");		label0=new JLabel("添加航班");		label1=new JLabel("航 班 号:");		label2=new JLabel("折    扣:");		label3=new JLabel("日    期:");		label4=new JLabel("年");		label5=new JLabel("月");		label6=new JLabel("日");		t=new JTextField(20);		t0=new JTextField(10);		t1=new JTextField(5);		t2=new JTextField(5);		t3=new JTextField(5);		ok=new JButton("添加");ok.addActionListener(this);		cancel=new JButton("取消");cancel.addActionListener(this);		init();		showMe();	}	public void init(){		JPanel p=new JPanel();		JPanel p1=new JPanel();		JPanel p2=new JPanel();		JPanel p3=new JPanel();		JPanel p4=new JPanel();		JPanel p5=new JPanel();		p1.add(label0);		p3.setLayout(new FlowLayout(FlowLayout.LEFT));		p4.setLayout(new FlowLayout(FlowLayout.LEFT));		p3.add(label1);p3.add(t);		p4.add(label2);p4.add(t0);		p.setLayout(new FlowLayout(FlowLayout.LEFT));		p.add(ok);p.add(cancel);		p5.add(label3);p5.add(t1);		p5.add(label4);p5.add(t2);		p5.add(label5);p5.add(t3);p5.add(label6);		p2.add(p3,BorderLayout.NORTH);		p2.add(p4,BorderLayout.CENTER);		p2.add(p5,BorderLayout.SOUTH);		this.add(p1,BorderLayout.NORTH);		this.add(p2,BorderLayout.CENTER);		this.add(p,BorderLayout.SOUTH);			}			private void showMe(){		this.setSize(300,250);		this.setVisible(true);		this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);//?	}	public void actionPerformed(ActionEvent e){		if(e.getActionCommand().equals("添加")){			//FlightDAO f=new FlightDaoFromFile("flightSchedular.dat");			FlightDAO dao = ServerMainClass.flightDaoSch;;			HashSet hs=(HashSet)dao.getAllFlightSchedulars();      //获得航班计划			System.out.println("查到的所有航班计划="+hs);						//有航班计划			if( hs.size()!=0){				//遍历				boolean b=false;			for(Object obj:hs){				FlightSchedular fsc=(FlightSchedular)obj;				//比较,存在次航班计划,则加入航班				if(fsc.getFlightNumber().equals(t.getText())){       					//存在所需航班计划,构造日期					Calendar date = Calendar.getInstance();					date.set(Calendar.YEAR, Integer.parseInt(t1.getText()));					date.set(Calendar.MONTH, Integer.parseInt(t2.getText()));					date.set(Calendar.DATE, Integer.parseInt(t3.getText()));										//创建航班					Flight f=fsc.createNewFlight(date,(Double.parseDouble(t0.getText())) );     //创建航班(日期,折扣)										System.out.println("创建的的航班:"+f);					boolean success=false;					success=ServerMainClass.flightDao.addFlight(f);        //加入航班						if(success){							JOptionPane.showMessageDialog(this,"添加航班成功!");							System.out.println("加入的航班是"+f);							b = true;							this.dispose();							return;						}				}			}//遍历结束			//无计划			if(!b){			JOptionPane.showMessageDialog(this,"指定日期没有航班计划,不能添加航班!");			this.dispose();			return;			}			//没有航班计划			}else{				JOptionPane.showMessageDialog(this,"没有航班计划,不能添加航班!");				this.dispose();				return;			}		}if(e.getActionCommand().equals("取消"))		      this.dispose();	  	}//方法结束}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -