Adding Items to Class Outline from the Text Editor

   

Although Visual J++ provides Class Outline and WFC Component Builder to help you add methods, member variables, properties, events, and classes to a project, you can also add these to your project by typing the code directly into your .java file from the Text editor. When you add the code for new classes and class members to a .java file, IntelliSense immediately displays the appropriate icon for the new class or class member in your project's Class Outline.

The following procedure demonstrates the dynamic updating of Class Outline when a new class and method is added to a source file from the Text editor.

Note   The code examples in this and the following topic, Adding Javadoc Comments to Source Files, were created with a Visual J++ Console Application project. You may use any existing Visual J++ project to reproduce the results of these scenarios. If you want to create a Console Application project for the following procedures, see Creating a Console Application and follow the steps to create and open the project before proceeding.

To add a new class to Class Outline from the Text editor

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

  2. Double-click the filename or icon of the .java file containing your project's main() method (Class1 .java by default).

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

  3. On the View menu, click Other Windows and select Document Outline from the cascading menu.

    Class Outline appears with a collapsed tree view of your file.

  4. From within the Text editor, after the closing brace of the class definition for Class1, add the following code to your .java source file:
    class Greeting
    {
    }
    
  5. In Class Outline, notice that a new class icon has been added to the tree view of your project's file for the Greeting class you've just created.

Note   When you use the Text editor to move the insertion point in the source file, Class Outline does not indicate which definition has been navigated to. To synchronize Class Outline with the source file, right-click the declaration in the Text editor and click Sync Class Outline on the shortcut menu.

To add a new method to Class Outline from the Text editor

  1. In Class Outline, expand the Greeting class to display the icons for Superclasses and Inherited Members.

  2. From within the Text editor, add the following code after the opening brace of the Greeting class:
    public static String hello()
    {
    String strGreet = new String("Hello World!");
    return strGreet;
    }
    
  3. In Class Outline, notice a new method icon has been added to your project for the hello() method you've just created.

Note   When you use the Text editor to move the insertion point in the source file, Class Outline does not indicate which definition has been navigated to. To synchronize Class Outline with the source file, right-click the declaration in the Text editor and click Sync Class Outline on the shortcut menu.

  1. To test the hello() method of the Greeting class, add the following code to your application's main() method:
    System.out.println(Greeting.hello());
    return;
    
  2. Build the program.

  3. In the Text editor, place the cursor on "return" (the last statement of this program's code). Click the right mouse button and select Run To Cursor from the shortcut menu.

  4. View the following results in JVIEW's console window:
    Hello World!

To add a Javadoc comment to the new hello() method, see Adding Javadoc Comments to Source Files.