Step 8.5: Modifying a Variable and Continuing


Step 8.5: Modifying a Variable and Continuing

click to expand

What I'd like you to do is to change the program so that it loops five times rather than three. How would you go about doing that? Well, the easiest way would be to change the count variable to the value 5, so let's do that.

q 8.5(a) Double-click on the count variable in the Variables view.

click to expand
Figure 8.31: Double-click on the count variable to modify it.

A dialog will pop up, as shown in Figure 8.32.

click to expand
Figure 8.32: The Set Variable dialog.

Use this dialog to change the value to 5.

q 8.5(b) Enter the value 5 and click OK.

click to expand
Figure 8.33: Updating the value.

You'll be returned to the workbench, where you will see that the value of the count variable has been changed to 5.

click to expand
Figure 8.34: The workbench, showing that count has changed to 5.

The last thing to do now is to restart the program and let it execute with the new value. There are several tool buttons in the Debug view that will allow you to single-step, step into a function, step out of a function, and so on. In this case, you simply want the program to resume execution (and presumably to finish). You can do this by using the Resume tool, as shown in Figure 8.35.

click to expand
Figure 8.35: The Resume tool of the Debug view will resume execution from the current point.

q 8.5(c) Click the Resume tool to continue execution of the program.

And the result? As you can see in Figure 8.36, the program now executes its loop five times, printing Hello 3 and Hello 4. This is exactly what we wanted to have happen, and thus our debugging was a success!

click to expand
Figure 8.36: The modified execution of the program, showing the two additional lines of output.

So now that you've managed to enter source code, run a program, set a breakpoint, and modify the execution, you're ready to use the tool to do some real programming. In the next two steps, you will build a simple user interface and then connect it to a database. By the time you are done, you will have built a functioning application!

Before we exit here, though, we have one last thing to do: return to the Java perspective. I think the easiest way will be to close the Debug perspective. Use the Perspective Bar on the left of the workbench.

q 8.5(d) Right-click on Debug in the Perspective bar and select Close.

click to expand
Figure 8.37: Closing the Debug perspective using the Perspective Bar.

This will close the Debug perspective and return you to the last open perspective, the Java perspective, as shown in Figure 8.38.

click to expand
Figure 8.38: Back to the Java perspective.

Okay, you've written, run, and debugged a very simple application. Time to put a little more meat on it. First, a user interface: that's the task for Step 9.




Eclipse
Eclipse: Step by Step (Step-by-Step series)
ISBN: 1583470441
EAN: 2147483647
Year: 2003
Pages: 90
Authors: Joe Pluta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net