Example #1
0
  // Method to open a file for sequential read-only.
  private void openFile() {
    // Define local primitive(s).
    String contents = new String();

    // If a file is open, prompt to save the file before dismissing content
    // and reference.
    if (!file.toString().equals("")) {
      // Close the existing file.
      closeFile();
    } // End of if file not null or not equal to a zero String.

    // Open a file.
    fileName = FileIO.findFile(this);

    // If a file name is returned.
    if (fileName != null) {
      // Read file.
      contents = FileIO.openFile(this, fileName);

      // Verify that the JTextAreaPanel is empty.
      if (sender.isTextAreaEmpty()) {
        // Set JTextAreaPanel.
        sender.setText(contents);

      } // End of if JTextAreaPanel is empty.
      else {
        // Reset JTextAreaPanel by replacing the range.
        sender.replaceRange(contents, 0, sender.getText().length());
      } // End of else JTextAreaPanel is not empty.

      // Set file open flag to true.
      fileOpen = true;
    } // End of if a fileName is selected.
  } // End of openFile method.