Running Code in the Scrapbook Example

This example demonstrates how to use the Scrapbook to run a fragment of code for testing or experimental purposes.

  1. Open the Scrapbook by selecting Scrapbook from the Windows menu of any IDE window.
  2. Copy and paste the following piece of code into a Scrapbook page:
  3. String selectedName; 
    String initialDirectory="C:";
    java.awt.FileDialog anOpener;
    
    anOpener=new java.awt.FileDialog(new java.awt.Frame(), 
                                     "Check file access rights", 0);
    anOpener.setDirectory(initialDirectory); 
    anOpener.show();
    
    selectedName = anOpener.getDirectory()+anOpener.getFile();
    
    java.io.File checkFile = new java.io.File(selectedName);
    if (checkFile.canWrite())
      {
      System.out.println("You have write-access to "
                          + selectedName+".");
      }
      else System.out.println("You have read-only access to " 
                               + selectedName+".");
    return checkFile; 
  4. Select the entire code fragment.
  5. Click the Run button runup.gif (1037 bytes).
  6. From the file dialog that is launched by the program, select a file and double-click on it.

The Console will output a message indicating whether you have write access or read-only access to the selected file.

ngrelc.gif (533 bytes)
The Scrapbook

ngrelt.gif (466 bytes)
Organizing Your Ideas in the Scrapbook
Experimenting with Code Fragments