WEB开发网
开发学院WEB开发Jsp Java Bean实现航空预定机票功能应用 阅读

Java Bean实现航空预定机票功能应用

 2008-01-05 10:49:07 来源:WEB开发网   
核心提示:概述:这是两个java bean应用的例子,实现航空预定机票的功能,Java Bean实现航空预定机票功能应用,预定构件功能说明:1,预定构件应包含二个面板,在已预定了所需座位号之后,给出所预定座位号的消息框应被显示d5,乘客面板应作为bean创建,预定座位面板与乘客面板2,在装入预定构件时不应有可用的乘客面板3

  概述:这是两个java bean应用的例子,实现航空预定机票的功能。
  
  预定构件功能说明:
  
  1,预定构件应包含二个面板,预定座位面板与乘客面板
  
  2,在装入预定构件时不应有可用的乘客面板
  
  3,当用户打入要预定的旅行地点.旅行日期及座位号时:
  
    (1)首先,应按以下格式生成乘客号:
  
    (2)其次,在显示乘客号时应使乘客面板是可见的(注重:你可能重定BeanBox窗口中bean大小,以观看此乘客面板。而且,假如打入座位号为0,则不应显示乘客面板。)
  
    (3)当用户点击乘客面板的submit按钮时,此面板的所有域控件中文本应置为空  
  
    (4)上面步骤被重复,直到所接收的乘客材料个数等于预定的座位数为止
  
  4,在已预定了所需座位号之后,给出所预定座位号的消息框应被显示d
  
  5,乘客面板应作为bean创建,可以把嵌入在铁路预定应用或航空应用中
  
  6,你需接受以下格式之一的旅行日期"dd/mm/yy","mm/dd/yy","dd-Month-yy"
  
  -----------------------------------------------
  
  /*1
  * PRogram file:  PsEvent.java
  * Creat time:  08/01/2004
  * Creat by:     InberKong
  * Last Modify time:
  * Modify by:   
  * Function describe: Event Class
  */
  import java.util.*;
  public class PsEvent extends EventObject
  {
   //
   public String number;
   public String name;
   public String address;
   public String phone;
  
   public PsEvent(Object source,String m1,String m2,String m3,String m4)
   {
   super(source);
   this.number=m1;
   this.name=m2;
   this.address=m3;
   this.phone=m4;
   }
  }
  
  ------------------
  
  /*2
  * Program file:  PsEventListener.java
  * Creat time:  08/01/2004
  * Creat by:     InberKong
  * Last Modify time:
  * Modify by:   
  * Function describe: Event listener
  */
  
  import java.util.*;
  public interface PsEventListener extends EventListener
  {
   public void psPerformed(PsEvent ev);
  }
  ---------------------------
  
  /*3
  * Program file:  PsBean.java
  * Creat time:  08/01/2004
  * Creat by:     InberKong
  * Last Modify time:
  * Modify by:   
  * Function describe: Passenger message bean
  */
  import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  public class PsBean extends JPanel implements ActionListener
  {
   JLabel lb_number;
   JLabel lb_name;
   JLabel lb_address;
   JLabel lb_phone;
   JTextField tf_number;
   JTextField tf_name;
   JTextField tf_address;
   JTextField tf_phone;
   JButton sbmt;
   PsEventListener pl;//声明事件监听
  
  
   public PsBean()
   {
   setLayout(new GridLayout(5,2));//设置布局治理器
  
   lb_number=new JLabel("Passenger Number:");//创建对象
   lb_name=new JLabel("Passenger Name:");
   lb_address=new JLabel("Passenger Address:");
   lb_phone=new JLabel("Passenger Phone:");
   
   tf_number=new JTextField(15);
   tf_name=new JTextField(15);
   tf_address=new JTextField(25);
   tf_phone=new JTextField(15);
  
   sbmt=new JButton("Submit"); 
   
   add(lb_number);
   add(tf_number);
   add(lb_name);
   add(tf_name);
   add(lb_address);
   add(tf_address);
   add(lb_phone);
   add(tf_phone);
   add(sbmt);
   sbmt.addActionListener(this);//监听事件
   tf_number.setEnabled(false); 
   }
  
  
   public void actionPerformed(ActionEvent evt)
   {
   Object obj=evt.getSource();
   if(obj==sbmt)
   {
    PsEvent ev=new PsEvent(obj,tf_number.getText(),tf_name.getText(),tf_address.getText(),tf_phone.getText());
    pl.psPerformed(ev);
   }
   
   }
  
   public void PsListener(PsEventListener el)
   {
   pl=el;
   }
   public void setPnrno(String ptemp)
   {
   tf_number.setText(ptemp);
   }
   
   public void refresh()
   {
   tf_number.setText("");
   tf_name.setText("");
   tf_address.setText("");
   tf_phone.setText("");
   }
  
  }
  
  ---------------------
  
  /*4
  * Program file:  Bpanel.java
  * Creat time:  08/01/2004
  * Creat by:     InberKong
  * Last Modify time:
  * Modify by:   
  * Function describe: Book panel bean
  */
  import java.beans.*;
  import javax.swing.*;
  import java.awt.event.*;
  import java.awt.*;
  public class Bpanel extends JPanel implements PsEventListener,ActionListener
  {
   JPanel pnl;
   BoxLayout blo;
  
   JLabel label_Date;
      JTextField text_Date;
       JLabel label_Place;
       JTextField text_Place;
       JLabel label_NOS;
       JTextField text_NOS;
       JButton button_Book;
    JLabel the_animation;
       String bank_Name="FlyMyWay Airlines";
       GridBagLayout gl_t;
       GridBagConstraints gbcs;
       
  //乘客面板javabean
  PsBean pb;
  
   int t_nos;
   int t_count;
   String t_passno;
  
      //Date format property with getter and setter methods  
      private String the_datFormat="mm/dd/yy";
      public String getDatFormat()
      {
         return the_datFormat;
      }
      public void setDatFormat(String temps)
      {
         the_datFormat=temps;
         if(the_datFormat=="mm/dd/yy")
            text_Date.setText("mm/dd/yy");
         if(the_datFormat=="dd/mm/yy")
            text_Date.setText("dd/mm/yy");
      if(the_datFormat=="dd-Month-yy")
     text_Date.setText("dd-Month-yy");
      }
      
      public Bpanel()
      {
   pnl=new JPanel();
   the_animation=new JLabel(bank_Name);
   label_Date=new JLabel("Enter Date of Travel:");
    text_Date=new JTextField(20);
    text_Date.setText(the_datFormat);
  
        label_Place=new JLabel("Enter Place of Travel:");
        text_Place=new JTextField(15);
   label_NOS=new JLabel("Enter Number of seats to be booked");
   text_NOS=new JTextField(5);
        button_Book=new JButton("BOOK SEATS");
  
    gl_t=new GridBagLayout();
   gbcs=new GridBagConstraints();
   pnl.setLayout(gl_t);
   
   gbcs.gridx=3;
   gbcs.gridy=10;
   gbcs.anchor=GridBagConstraints.NORTHWEST;
   gl_t.setConstraints(the_animation,gbcs);
   pnl.add(the_animation);
  
   gbcs.gridx=2;
   gbcs.gridy=20;
   gbcs.anchor=GridBagConstraints.NORTHWEST;
   gl_t.setConstraints(label_Date,gbcs);
   pnl.add(label_Date);
   
   gbcs.gridx=4;
   gbcs.gridy=20;
   gbcs.anchor=GridBagConstraints.NORTHWEST;
   gl_t.setConstraints(text_Date,gbcs);
   pnl.add(text_Date);
  
   gbcs.gridx=2;
   gbcs.gridy=30;
   gbcs.anchor=GridBagConstraints.NORTHWEST;
   gl_t.setConstraints(label_Place,gbcs);
   pnl.add(label_Place);
   
   gbcs.gridx=4;
   gbcs.gridy=30;
   gbcs.anchor=GridBagConstraints.NORTHWEST;
   gl_t.setConstraints(text_Place,gbcs);
   pnl.add(text_Place);
  
   gbcs.gridx=2;
   gbcs.gridy=40;
   gbcs.anchor=GridBagConstraints.NORTHWEST;

Tags:Java Bean 实现

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接