Exercise 2: Setting a Breakpoint
Setting a breakpoint is useful in tracking down a trouble spot in your program. In this exercise, you will use the Source Editor to set a breakpoint in Blink.java while the program is running. The program runs to the breakpoint and stops.
The source line numbers given in this tutorial assume you have added the additional code given in Editing Source Code.
- In the Source Editor, move the pointer to line 45:
if (x + w > d.width) {
The above line was chosen so you can track the change in the values of variables as the program goes through the loop. In most cases, you will set a breakpoint in a line where you think a bug occurs in your program.
- Click the Toggle Breakpoint control
on the Source Editor tool bar.
The Java WorkShop sets a breakpoint in the line and runs the program until it reaches the breakpoint. The line containing the new breakpoint changes to green to indicate where program execution stopped. The applet stops running in the Applet Viewer and the Threads/Stack tab is updated. The method in which program execution stopped is also highlighted in the Threads/Stack tab.
Next lesson:
- Exercise 3: Examining Threads