- Complete Closed Lab 1 if you haven't already done so.
- Continue experimenting with Display_a_Window.kpl according to the
following instructions. Write
(or print) out answers to all questions asked (16, 17, 18, 20, and 24).
- If you've just started Phrogram again and loaded
Display_a_Window.kpl, then you probably don't yet see the body of
Method Main()! Just click on the plus sign appearing to the left
of Method Main() to open the body of Main() so you can see it and edit
it. Insert a new line into the program just above the line that
starts with "Status". This new line should look like the
following:
Trace( "Out of sight! This program has started running!" )
- If you wish, you can also change "Our first Phrogram program" to
"A Phrogram program".
- Run (which automatically saves) this changed program.
- Look in the Messages sub-window to see the effect of method
Trace(). Note that programmers call commands like Status() and
Trace() "methods", and that they often place an empty pair of
parentheses after the method's name when they're writing about a program to indicate to
their reader that it is the name of
a method (or of a function). A function is similar to, but
different than, a method, but more on that later.
- Close the stopped program's window.
- Programmers often wish to experiment with a program by, say,
removing one or more lines from the program. However, they may
later wish to put one or more of those lines back in. They can
accomplish this task efficiently by "commenting out" the lines to be
(temporarily) removed. That is to say, they turn these lines into
comments. Later, they can remove the comment symbols to put those
lines back in the program. These actions are so handy that this
ability is built into many IDEs, including Phrogram's.
- Comment out the line beginning with "Status" by dragging the
mouse from the beginning of Status to the end of the line. Then,
on the toolbar, click the button
that has horizontal lines in it,
some
black and some light blue.
- Run this changed program and observe what's different.
- Now uncomment the line beginning with "Status" to put it back
into the program. Do this by dragging the mouse from the
beginning of the comment to the end of the line. Then, on the
toolbar, click the button
that has the curving arrow in it.
- Run this program and note that it now behaves just as it did
before you commented out the line beginning with "Status".
- Now insert two new lines into the program just after the line that starts with
"Status". These new lines should look like the following:
Alert( "Click OK to continue. This program run is about to end.", "Good-bye!" )
Trace( "Program ends, but window stays open." )
- If you wish, you can also change "A Phrogram program" to "Mission
accomplished!".
- Run this changed program.
- Before clicking on OK to continue, look at the window containing
the OK button. Can you find the text "Good-bye!"? Look
everywhere! Tell me where it is.
- Now look in the Messages window. Have all messages from
calls to method Trace() come out yet?
- What do you conclude about the order in which a programmer lists
calls to methods? Does the order matter? If so, how?
- As you can probably guess from 17. and 18. above, when a
programmer mentions a method, she says she "calls" it.
"Hello? Is Status there? Hi Status! Could you please
put this message on the bottom of the application window?" In the
current program, method Main() consists of a list of four method calls.
- Now click OK to continue and look again in the Messages
window. Is your conclusion about the order of method calls in a
list confirmed by what you see? Well, it happens pretty
fast. Try to notice what's there before you click OK and what's
there afterward. After closing the stopped program's window, run
the program again if you need to!
- Close the stopped program's window.
- Replace the last two of the four method calls in Main() with the
following four calls:
Alert( "Click OK to continue. This window will close.", "Good-bye!" )
Trace( "Closing window . . ." )
Stop()
Trace( "This message should not appear!" )
- Run this changed program, carefully observing its behavior.
- What do you infer the behavior of method Stop() to be?
- Now close Display_a_Window.kpl by right-clicking on its tab and
selecting Close from the list.
- Now open a different pre-existing program by performing the
following steps:
- In the Files view in the right-hand side of the window, open
folder "OSU" by double clicking on it.
- Find file "001 Display_a_Window.kpl" and open it by double
clicking on it.
- Notice in this program that there are many comments, some of them
rather long. It can become rather tedious to type "//" as the
first characters of every line of a long comment. Hence one other
way of denoting comments is available in Phrogram programs.
Before reading ahead, can you guess by looking at this program what
that way is?
- That's right: "/*" marks the beginning of a comment; that comment
comes to an end with "*/".
- You should now be able to open Display_a_Window.kpl again by
finding it in the "0) My Own" folder.
- Now you have two tabs open in Phrogram. You can switch back
and forth between these programs by clicking on their tabs.
- You can now close the longer file "001 Display_a_Window.kpl", the
one
with all those many comments, by
right-clicking on its Display_a_Window.kpl
tab and selecting "Close all other programs".
- You could have exited Phrogram with two or more tabs up, or with
zero tabs up. However, why not exit Phrogram now with one tab
up? In any case, the next time you launch Phrogram, it will come
up with the same number of tabs open as when you left it.
- Read the syllabus,
and bring to class any questions you have about it.
- Congratulations upon finishing all 34 steps of Homework 1!
Whenever you wish, feel free to experiment with Phrogram as much as you
want. (For example, what happens when you comment out some other
lines of the program, such as the "Program" line or an "End Method"
line?) Also, if you want to get excited about what you could do
with Phrogram later in the course, please visit http://www.phrogram.com.