|
To access the contents, click the chapter and section titles.
Sams Teach Yourself Visual J++ 6 in 21 Days
The Watch WindowStart a debug session by pressing F11 until you get to the initForm() method. Youll 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 its not, go to View, Debug Windows. One of the choices youll see is Watch. If you select this option and youre 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 youre in a debug session, heres 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 variables 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.
If you add a variable that doesnt exist, or a variable thats out of scope, youll 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 WindowThe 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.
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.
The Autos WindowThe 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.
The Immediate WindowThe 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. Thats 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.
The Call Stack WindowThe 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 wont be open by default. To open it, select View, Debug Windows, Call Stack.
|
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. |