Displaying the Port Description


The ShowDescriptionWindow.java file displays the name, type, mode, status, and owner of the selected port get from the PortDescription.java file. The ShowDescriptionWindow.java file displays the description of the selected port in a tabular format.

Listing 2-2 shows the contents of the ShowDescriptionWindow.java file:

Listing 2-2: The ShowDescriptionWindow.java File

start example
 /* Imports required AWT classes. */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; /* class ShowDescriptionWindow -  This class is the sub class of the application.  This class displays the table of port description. */ class ShowDescriptionWindow extends JFrame  {    /* Declare the String objects. */    private String porttype;    private String portstatus;    private String ownername;    private String portname;    private String portexists;     private String pmode;    Border tableborder;    /* Declare the JButton object. */    JButton okbutton;    /* Declare the JTable object. */    JTable table;    /*     Declare the default constructor of the FileList class.    */    public ShowDescriptionWindow()    {       /* Set title of parent frame. */       super("Port Description");       porttype="Unknown port";       portstatus="Not Open";       ownername="";       portname="";       portexists="No";       pmode="";    }    /*    setPortType - This method sets the value of porttype field.    Parameters: ptype - a String object containing port type.    Return Value: NA    */    public void setPortType(String ptype)    {       porttype=ptype;    }    /*    isPortOpen - This method sets the value of portstatus field.    Parameters: openornot - a String object containing YES or NO.    Return Value: NA    */    public void isPortOpen(String openornot)    {       portstatus=openornot;    }    /*    ownerName - This method sets the value of ownername field.    Parameters: openornot - a String object containing owner name.    Return Value: NA    */    public void ownerName(String oname)    {       ownername=oname;    }    /*    portName - This method sets the value of portname field.    Parameters: pname - a String object containing port name.    Return Value: NA    */    public void portName(String pname)    {       portname=pname;    }    public void setPortMode(String portmode)    {       pmode=portmode;    }    /*    portNotExists- This method sets the value of portexists field.    Parameters: exists - A String object containing information of port validity.    Return Value: NA    */    public void portNotExists(String exists)    {       portexists=exists;    }    /*    enableDisableOpenButton - This method opens a window     which contains a port description table and ok button.    Parameters:    pd - a JFrame object.    Return Value: NA    */    public void showMessage(JFrame pd)    {       /*        Initialize and set the look and feel of the application to Windows Look and Feel.       */       try        {          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());       }        catch(Exception e)       {          System.out.println("Error setting window LAF: " + e);       }       /* Get the content pane of this class. */       Container messagewindowpane=getContentPane();       /*        Set the layout of the frame as Null.        */       messagewindowpane.setLayout(null);       /*        Set the background color as white.        */       messagewindowpane.setBackground(Color.white);       /*        Initialize a new button and add to content pane.       */       okbutton=new JButton("OK");       messagewindowpane.add(okbutton);       okbutton.setActionCommand("ok");       okbutton.addActionListener(new ActionListener()        {          /*          actionPerformed - This method is called when the user clicks the Ok button.          Parameters:             ae - an ActionEvent object containing details of the event.          Return Value: NA          */          public void actionPerformed(ActionEvent e)           {              ShowDescriptionWindow.this.dispose();          }       });       addWindowListener(new WindowAdapter()       {          /*          windowClosing - This method is called when the user clicks the X button on the top bar.          Parameters:             e - an WindowEvent object containing details of the event.          Return Value: NA          */          public void windowClosing(WindowEvent e)          {              ShowDescriptionWindow.this.dispose();          }       });       /*       Declare a Point object and initialize it with the getLocation() method       */       Point p=pd.getLocation();       /*        Set default location for this frame.        */       setLocation((int)p.getX(), (int)p.getY());       /*       Declare Dimension object and initialize it with the getPreferredSize() method.       */          Dimension size=okbutton.getPreferredSize();       okbutton.setBounds(140, 180, size.width, size.height);       /*        Declare and initialize the Object array.        */       Object[][] rowdata={{" Port Type",porttype},{" Port Name",portname},       {" Port Mode",pmode},{" Port Status",portstatus},{" Owner Name",ownername}};       /*        Declare and initialize the String array.        */       String[] columnname={"Text","Description"};        table=new JTable(rowdata,columnname);       messagewindowpane.add(table);       size=table.getPreferredSize();       tableborder=new EtchedBorder(EtchedBorder.RAISED);       table.setBorder(tableborder);       table.setBounds(50, 28, 250, size.height);       setSize(350,250);                setVisible(true);    } } 
end example

Download this listing.

The above listing displays the description of the selected port. The ShowDescriptionWindow.java file creates a table that displays the description of the selected port.




Developing Applications Using JCA
Developing Applications Using JCA
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 43

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