Showing the Airline Schedules


The ReservationResultTable.java file shows the available airline schedules in the user interface of the Airline Reservation application. Listing 6-6 shows the contents of the ReservationResultTable.java file:

Listing 6-6: The ReservationResultTable.java File

start example
 /* Imports required classes from javax.swing package */ import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; /* Imports required classes from javax.swing.table package. */ import javax.swing.table.*; /* Imports required classes from javax.swing.event package. */ import javax.swing.event.*; /* Imports required classes from javax.swing package. */ import javax.swing.*; /* Imports required classes from java.awt package. */ import java.awt.*; /* Imports required classes from java.awt.event package. */ import java.awt.event.*; /* class SocketClass - This class is used for reading the input messages and writing output messages.  Constructor: SocketClass - This constructor calls a method of SocketOpener class to open a client socket. Methods: */ public class ReservationResultTable extends JPanel  {    /*    Declare the object of the ReservationTableModel class.    */    ReservationTableModel tablemodel;    /* Declare the object of the JTable class.*/    JTable table;    public ReservationResultTable()     {       super(new GridLayout(1,0));       /*       Initializes the object of ReservationTableModel class.       */       tablemodel=new ReservationTableModel();       /*       Initializes the object of JTable class.       */       table = new JTable(tablemodel);       table.setPreferredScrollableViewportSize(new Dimension(600, 100));       /* Declare and initialize the object of JScrollPane class.*/       JScrollPane scrollPane = new JScrollPane(table);       add(scrollPane);       setPreferredSize(new Dimension(600, 100));    }    /*    class ReservationTableModel - This class is used to insert data into table.    Methods:    getColumnCount - Returns number of column in the table.    setData - Set data into table cell.    getRowCount -gets number of rows in the table.    isCellEditable - Set cell edit property.    setValueAt - Set data into table cell.    */    class ReservationTableModel extends AbstractTableModel     {       private String[] columnNames = {"Choice","Flight No.",       "Aircraft type",       "Origin",       "No. of Stops",       "Destination",       "Dep.Date-time",       "Arr.Date-time",       "Executive Class",       "Economy Class",    };    private Object[][] data = {};    /*    getColumnCount - Returns number of column in the table.    Parameter: N/A    Return Value: int    */    public int getColumnCount()     {       return columnNames.length;    }    /*    setData - Set data into table celles.    Parameter: dataarr - array of Object Type.    Return Value: int    */    public void setData(Object[][] dataarr)    {       data=dataarr;    }    /*    getRowCount -gets number of rows in the table.    Parameter: dataarr - array of Object Type.    Return Value: int    */    public int getRowCount()    {       return data.length;    }    /*    getColumnName - Returns Column name    Parameter: col    Return Value: String    */    public String getColumnName(int col)     {       return columnNames[col];    }    /*    getValueAt - Returns value from a table cell.    Parameter: row, col    Return Value: Object    */    public Object getValueAt(int row, int col)     {       return data[row][col];    }    /*    getColumnClass - Returns the Class of a table cell.    Parameter: col    Return Value: Class    */    public Class getColumnClass(int col)     {       return getValueAt(0, col).getClass();    }    /*    isCellEditable - Set cell edit property.    Parameter: row, col    Return Value: boolean    */    public boolean isCellEditable(int row, int col)     {    if (col >=1&&col<=7)     {       return false;    }    else    {       return true;    } } /* setValueAt - Set data into table cell. Parameter: value - Object of Object type, row, col Return Value: N/A */ public void setValueAt(Object value, int row, int col)  {    data[row][col] = value;    fireTableCellUpdated(row, col); } } } 
end example

Download this listing.

In the above code, the constructor of the ReservationResultTable class creates a new instance of the ReservationTableModel class. The ReservationTableModel class shows the matched airline schedules received from the Jabber server in a tabular format.

The methods defined in Listing 6-6 are:

  • getRowCount(): Returns the total number of records present in the search result.

  • isCellEditable(): Checks whether or not the information received from the Jabber server is editable.

  • setValueAt(): Shows the matched airline schedules in the user interface of the Airline Reservation application.

The ReservationResultTable.java file shows the airline schedules in the main window of the Airline Reservation application, as shown in Figure 6-4:

click to expand: this figure shows the available airline schedules in a tabular format. end users can select any schedule and click the submit button to reserve the selected airline schedule.
Figure 6-4: Showing the Airline Schedules

A confirmation message appears when an end user clicks the Submit button, as shown in Figure 6-5:

click to expand: this figure shows the confirmation message that appears after an end user successfully submits the selected airline schedule to the jabber server.
Figure 6-5: Confirmation Message




Developing Applications Using Jabber
Developing Applications Using Jabber
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 68

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net