Java bean application - booking components (INBER original)

zhaozj2021-02-16  105

Overview: This is an example of two Java Bean applications that achieve the function of aviation reservation ticket.

Predetermined component function description:

1. The predetermined component should contain two panels, scheduled seating panels and passenger panels

2, should not have available passenger panels when loading a predetermined component

3. When the user is hits the travel location to be scheduled. Travel date and seat number:

(1) First, the passenger number should be generated in the following format:

(2) Second, the passenger panel should be visible when the passenger number is displayed (Note: You may refine the Bean size in the Beanbox window to watch this passenger panel. Moreover, if the seat number is 0, the passenger should not be displayed. panel.)

(3) When the user clicks the Submit button of the passenger panel, all domain controls in this panel should be empty

(4) The above steps are repeated until the received passenger material is equal to the predetermined number of seats.

4. After the desired seat number has been predetermined, the message box for the predetermined seat number should be displayed D.

5, the passenger panel should be created as bean, which can be embedded in the railway scheduled application or aviation application.

6, you need to accept one of the following formats "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; // Declaration event monitor public psbean () {setLayout (New GridLayout (5, 2)); // Settings Layout Manager LB_Number = New Jlabel ("Passenger Number:"); // Create Object 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 (lb_name); add (tf_name); add (lb_address); add (lb_phone); add (tf_phone); Add (SBMT); SBMT.AddActionListener (this); // Listen to the event TF_NUMBER.SETENABED (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; // passengers panel javabeanPsBean 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_AMATION = 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_AMATION, GBCS); pnl.add (the_animation);

GBCS.Gridx = 2; gbcs.griDy = 20; gbcs.anchor = gridbagconstraints.northwest; gl_t.setconstraints (label_date, gbcs); pnl. agidx = 4; gbcs.gridx = 20; GBCS. Anchor = gridbagconsts.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. agidx = 4; gbcs.gridy = 30; GBCS. Anchor = gridbagconstros.northwest; gl_t.setconstraints (text_place, gbcs); pnl.add (Text_Place);

GBCS.Gridx = 2; gbcs.gridy = 40; gbcs.anchor = gridbagconstraints.northwest; gl_t.setconstraints (label_nos, gbcs); pnl.gridx = 4; gbcs.Gridy = 40; GBCS. Anchor = gridbagconstros.northwest; gl_t.setconstraints (text_nos, gbcs); pnl.add (Text_nos);

gbcs.gridx = 3; gbcs.gridy = 50; gbcs.anchor = GridBagConstraints.NORTHWEST; gl_t.setConstraints (button_Book, gbcs); pnl.add (button_Book); button_Book.addActionListener (this); textDisplay (); pb = new PSBean (); pb.pslistener (this);

BLO = New BoxLayout (this, BoxLayout.y_AXIS); this.SetLayout (blo); blo.addlayoutcomponent ("Booking Panel", PNL); Blo.addLayoutComponent ("Passenger Panel", PB); this.Add (PNL); THIS.Add (PB); Pb.setVisible (false);} public void textdisplay () {font f = new font ("Times New Roman", Font.Bold, 30); The_animation.setFont (f); the_animation.settext (bank_Name);} public void actionPerformed (ActionEvent evt) {Object obj = evt.getSource (); try {if (Integer.parseInt (text_NOS.getText ()) == 0) JOptionPane.showMessageDialog (this, new String ( " Number of passengers> 0 "); if (Obj == Button_book && (Integer.Parseint ())> 0) {text_date.setenabled (false); text_Place.senabled (false); text_nos.setenabled ( false); button_Book.setEnabled (false); t_count = 1;.. t_passno = text_Place.getText () trim () text_Date.getText () trim () String.valueOf (t_count); t_nos = Integer.parseInt (text_NOS .getText ()); Pb.SETPNRNO (T_Pa ssno); pb.setVisible (true);}} catch (Exception e) {JOptionPane.showMessageDialog (this, new String ( "NumberFormat For input string is wrong, plese check it!"));}} public void psPerformed (PsEvent EVT) {t_count ; if (t_count <= t_nos) {t_passno = text_Place.getText (). Trim () text_date.getText (). Trim () String.Valueof (t_count); pb.refresh (); PB. setPnrno (t_passno);} else {pb.setVisible (false); t_count--; JOptionPane.showMessageDialog (this, new String ( "Number of Passenger Added:" t_count)); text_Date.setText (the_datFormat); text_Place.setText ("

"); Text_nos.setText (" "); text_date.setenabled (TRUE); TEXT_PLACE.SETENABED (TRUE); TEXT_NOS.SETENABED (TRUE); button_book.setenabled (TRUE); pb.refresh (); t_nos = 0; t_count = 0;}}} ------------------

/ * 5 * Program file: App.java * Creat Time: 08/01/2004 * Creat by: Inberkong * Last Modify Time: * Modify by: * Function Describe: Flymyway Airlines * / Import Javax.swing. *; Import Java .awt.event. *; import java.awt. *; public class app extends jframe {bpanel panel = new bpanel (); // javabean public app () igtContentPane (). Add (panel); this.pack (); This.setVisible (TRUE); public static void main (string args []) {new app ();}} ------------------

If your friends can't see the effect, I can put the hair. If you have reprint, please contact me.

转载请注明原文地址:https://www.9cbs.com/read-11471.html

New Post(0)