Creating the Help File

The file enables you to create the Help window of the File Search application. This window displays the steps to use the File Search application to the end user .

Listing 4-3 shows the contents of the file:

Listing 4-3: The File
start example
 /* Import the packages to use their classes in this class. */ import java.awt.event.*; import java.awt.FlowLayout; import java.awt.Font; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JDialog; /* A class for the Help file. */ public class Help extends JDialog implements ActionListener {    JLabel label1;    JTextArea area;    JScrollPane sp;    JPanel pane;    String str;    String text;    JButton ok;    GridBagLayout gbl;    GridBagConstraints gbc;    /*    Define the default constructor of the Help class.     */    public Help()    {       /*       Set the size. Initialize the panel and set the layout. Add this panel to the frame.       */       setTitle("Help");       setSize(460, 260);       setVisible(true);       setResizable(false);        gbl = new GridBagLayout();       getContentPane().setLayout(gbl);       gbc = new GridBagConstraints();       /*       Initialize the Label. Add the label to the panel.       */       gbc.gridx = 1;        gbc.gridy = 1;       gbc.gridwidth = 1;       gbc.gridheight = 1;       gbc.anchor = GridBagConstraints.CENTER;       label1 = new JLabel("File Search Utility Help");       Font f = new Font("Veradan",Font.BOLD,14);       /*       Set the Font style and size of the label caption.        */       label1.setFont(f);       getContentPane().add(label1, gbc);       /*       Create a text area and set the text.       Set the font as Verdana in the text area.       Set editable false in the text area.       Add this text area to the scroll pane.       */       gbc.gridx = 1;        gbc.gridy = 2;       gbc.gridwidth = 1;       gbc.gridheight = 1;       gbc.anchor = GridBagConstraints.CENTER;       area = new JTextArea(10, 40);       text = "The steps to search for a file are:\n\n"       + "1. Click the Browse button to locate a directory.\n"       + "2. Enter the text that you want to search in the Containing text text box.\n"       + "3. Click the Search button to start the search process.\n"       + "4. Click the Cancel button to stop the search process before it is complete.";       Font f1 = new Font("Veradan",Font.PLAIN,12);       area.setFont(f1);       area.setText(text);       area.setLineWrap(true);       area.setWrapStyleWord(true);       area.setEditable(false);       sp = new JScrollPane(area);       getContentPane().add(sp, gbc);       /*       Initialize the OK button. Add action listener.       */       gbc.gridx = 1;        gbc.gridy = 3;       gbc.gridwidth = 1;       gbc.gridheight = 1;       gbc.anchor = GridBagConstraints.CENTER;       ok = new JButton(" OK ");       ok.addActionListener(this);       getContentPane().add(ok, gbc);           }    /*    actionPerformed() This method is called when the end user clicks the OK button.    Parameters:    ae - An ActionEvent object containing information about the event.    Return Value: NA    */    public void actionPerformed(ActionEvent ae)    {       /*       This is executed when the end user clicks the Search button.       */       if(ae.getSource() == ok)       {          this.setVisible(false);       }    } } 
end example

Download this Listing .

In the above listing, the Help() constructor creates the Help window, as shown in Figure 4-3:

click to expand: this figure shows the help window, which displays the steps to search for files using the file search application.
Figure 4-3: The Help Window

When an end user clicks the OK button on the Help window, the actionPerformed() method is invoked. This method sets the visibility of the Help window to False and closes the window.

Java InstantCode. Developing Applications Using Java NIO
Java InstantCode. Developing Applications Using Java NIO
Year: 2004
Pages: 55 © 2008-2017.
If you may any questions please contact us: