home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Sams Teach Yourself Visual J++ 6 in 21 Days
(Publisher: Macmillan Computer Publishing)
Author(s): Rick Leinecker
ISBN: 0672313510
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


The Watch Window

Start a debug session by pressing F11 until you get to the initForm() method. You’ll notice that you step through the newly added code that declares and initializes variables.

By default, the Watch window is open when Visual J++ is in a debug session. If it’s not, go to View, Debug Windows. One of the choices you’ll see is Watch. If you select this option and you’re in a debug session, the Watch window will open. You can look at variables in the Watch window. It displays the variable name, contents, and type.

Assuming you’re in a debug session, here’s how you add a variable to the Watch window. Type the variable name exactly as it appears in your source code in the Name column of the watch window. The variable’s value and type will appear.

Try adding the m_nHorizontal variable to the Watch window. The value will be 50 and the type will be int. Your Watch window will look like the window shown in Figure 4.2.


Figure 4.2   You can easily add variables to the Watch window by entering the variable name in the Name column.

If you add a variable that doesn’t exist, or a variable that’s out of scope, you’ll see Error: symbol ‘xxxx’ not found (xxxx being the name of the variable you typed). Remember: The scope of a variable begins immediately where it is declared and ends with the closing brace (}) of the block of code it is declared within. For more information, look back to the Scope section on Day 2, “Java Language Fundamentals.”

The Locals Window

The Locals window displays the local variables and their values in the current stack frame. The current stack frame reflects the local variables, any parameters that have been passed to the method, and methods that have called this method. As the execution switches from procedure to procedure, the contents of the Locals window change to reflect the local variables applicable to the current procedure.

The Locals window is updated only when execution is stopped. Values that have changed since the last break are highlighted as shown in Figure 4.3.


Figure 4.3   The Locals window shows you the local variables in the current method.

In the Locals window you can change the current stack frame within the active thread by selecting it from the Context list. You can also drag a selected variable to the Immediate window or the Watch window. To edit a variable, double-click it. You can click the “+” or “-” to view or hide the member variables of an object variable or array. You can also use the keystrokes listed in Table 4.2 to view or hide member variables of the selected object or array or to move around in the Locals window.

Table 4.2 Locals Window Actions

Action Keystroke

Collapse the member variables list Left-arrow key
View the member variables Right-arrow key
Toggle between hiding and viewing the variables Enter
Move upward in the member variables list Up-arrow key
Move downward in the member variables list Down-arrow key
Move up an expanded list Left-arrow key
Move down an expanded list Right-arrow key

The Autos Window

The Autos window displays the values of all variables that are within the scope of currently executing procedures. Whereas the Locals window shows variables for a single thread, the Autos window shows variables for all threads. This window allows you to learn about the changes to a variable that might be caused by code executing on a different thread. A variable remains visible as long as it is in scope, reflecting any changes to its value. When the variable goes out of scope, it is removed from the Autos window.

In Figure 4.4, you can see the Autos window. It contains the global variables from our LearnToDebug applet.


Figure 4.4   The Autos window here contains the global variables we added to our LearnToDebug application.

The Immediate Window

The Immediate window is used to enter expressions to be evaluated or executed by a development language. The rules for entering expressions and the behavior of the Immediate window are dependent on the Java language.

Start a debugging session and step into the initForm() method. In the Immediate window, type m_nHorizontal. On the next line, the value of 50 will be printed. This shows you that the value of m_nHorizontal is 50. That’s not too useful, though, because we can see that information in the Watch window. But if you type m_nHorizontal * 8, the debugger prints 400 on the next line. You can just as easily type m_nHorizontal * m_nVertical for a value of 3750, as shown in Figure 4.5. The Immediate window is a great opportunity to evaluate expressions that will help you debug your program.


Figure 4.5   The Immediate window lets you evaluate expressions.

The Call Stack Window

The Call Stack window displays a list of all active procedures or stack frames for the current thread of execution. Active procedures are the uncompleted procedures in a process.

In the Call Stack window, you can change the active thread by selecting it from the threads list. You can also change the size of the column header by dragging its border to the right to make it larger or to the left to make it smaller. Double-clicking a row allows you to change the contents of the Locals window to correspond with the selected procedure. Change the size of a column by dragging the border of the column header to the right to make the column larger or to the left to make it smaller.

The threads list contains a list of all threads in the current process. Selecting a thread from the list gives the thread the focus in IDE. The list of threads is the same as the list that appears in the Threads window.

The Call Stack window won’t be open by default. To open it, select View, Debug Windows, Call Stack.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.