Creating Statements with Word Completion

   

For the examples in this topic, Word Completion provides visual clues when you're typing the name of String and System classes, and creating a new String object. Word Completion is available for any Visual J++ project.

Note   The code examples in the following scenario were created with a Visual J++ Console Application project. If you would like to create a Console Application project to complete this scenario, see Creating a Console Application and follow the steps to create and open the project before proceeding.

To select an item from a list provided by the Word Completion feature

  1. On the View menu, click Project Explorer") to open Project Explorer.

  2. In Project Explorer click the plus ("+") sign to the left of your project's name to expand your project.

  3. Highlight the .java file containing your project's main() method (Class1.java by default) and select View Code from the shortcut menu.

    Visual J++ opens the Text editor and loads your .java file. The file is now ready for editing.

  4. To get Word Completion assistance for the String class, type an "S" between the braces of the application's main() method and leave the cursor to the right of this letter.

    Tip   Notice the red squiggly line drawn under the letter. Since an "S" has no significance within the context of this program, IntelliSense gives a visual clue for the syntax error. For more information about visual editing clues, see Finding Errors with Dynamic Syntax Checking.

  5. On the Edit menu, click Complete Word to display a list box of classes and other elements recognized by IntelliSense.

    Tip   You can use the keyboard shortcut, CTRL+SPACE, instead of selecting the Complete Word option on the Edit menu, to display this list box.

  6. With the list box still displayed, type a "T" after the "S" of the statement you're building in your .java file.

    Statement Completion now selects StackOverflowError in its list — the first element that starts with an "ST" in the context of this program.

  7. Now type an "R" after the "ST" in your statement and Statement Completion moves the highlight bar to String in the list box.

  8. Press the Tab bar to insert "String" into the statement you're building.

    Pressing the Tab bar or any other non-alphanumeric key, such as a period or opening parenthesis, places the selected item into a statement at the location of the insertion point.

    Tip   Instead of typing the letters until Statement Completion finds the element you need, you can use the up and down arrows to highlight your selection.

To select a class name after the new operator

  1. Continue to build the statement by typing the following code after "String":
    [String] myStr = new 
    
  2. Type a space after "new" and Statement Completion automatically displays a list of class names available within the scope of your program.

  3. Type "STR", or enough letters of "String" to select the String item from the list.

  4. Press Tab and "String" is inserted after "new".

    Your statement should look like this:

    String myStr = new String
    

To continue building the statement that displays a line of text, you'll need a constructor for the new String object. See Selecting an Overloaded Method for a procedure that selects a String constructor with Statement Completion's Parameter Info option.

If you know how to partially spell the name of the class or item, use the following procedure to speed up the process of typing and selecting the correct spelling and capitalization.

To finish typing a word using the Word Completion feature

  1. In your .java file, move the cursor to a new line and type "SY".

  2. Press CTRL+SPACE (the Word Completion keyboard shortcut).

    Statement Completion completes the word, "System", and inserts it into your code since it is the only item that begins with an "SY". If more than one item starts with these letters, Statement Completion displays a list box.