Subject: homework 5 update

From: Kenneth Been <[email-masked]>
Date: Tue, 17 Nov 1998 17:41:44 -0500

Basic Algorithms Class:

I'm afraid that there might be some confusion caused by the way that
Java does the painting to the screen, which is asynchronously.  In other
words (if I understand it right myself---no certainty) when repaint() is
called, the program may just continue executing, and the repaint will
happen some time in the future, after your program has done some other
stuff.  This is why I am suggesting that you put much of the program
logic in the paint() method, since code within that method will just be
executed in the normal fashion.

So, I have rewritten my example to show you a way to deal with this. 
The new url for the directory is

http://cs.nyu.edu/been/v22.0310-004/eg/hw5example/

I will explain the various methods, and what they do:

init():
    This is the method that is called when the applet is first loaded
into the browser.  I just create the array, set some colors, and create
the url object that will be needed for reading the input.

start():
    This is the method that is called after init(), and whenever the
browser returns to this page after visiting another.  I open the input
stream, and then mark the beginning, so that we can return to the
beginning of the file and re-read it later.

stop():
    This is the method that is called whenever the browser leaves the
page to visit another.  I just close the input stream.  (So the idea is
that the input stream is opened when the browser visits the page, and
closed when the browser leaves.  In between we will do the reading in
the paint() method.)

paint():
    This is the method that is called whenever the applet needs to be
redrawn to the screen, which could be after start(), or even just when
another window that has covered up the browser is removed, so the
browser is on top again.  So paint() might be called several times
without calling start() or stop().  That is why we will need to reset
the input stream to read from the beginning.  (An alternative would be
to open it, read it, and close it, all within paint(), but that would be
less efficient, and would make the paint() method longer and more
confusing.)

    In paint(), I first reset the input stream so that we will read from
the beginning of the file.  Next I initialize some variables.  Then, I
go through a loop in which I read in a line, store it in the array, and
print out the current contents of the array (by calling snapshot()).

Notice that the calls to snapshot all happen during one execution of
paint(), which means that they will be done in a predictable manner.

You are welcome to use any code from this example.  I suppose the parts
on dealing with the input stream will be most useful.  You still need to
implement a heap, insert the elements in the right manner, sort, etc.

Ken

---

From: Edward Ryklin <[email-masked]>
Date: Sun, 22 Nov 1998 15:39:10 -0500

url = new URL(getDocumentBase(), "input.txt");

works great, i recommend everyone use this!

---

From: Kenneth Been <[email-masked]>
Date: Mon, 23 Nov 1998 12:18:19 -0500 (EST)

If the two operands to / are integers then it will return an integer.

\ is not an operator in Java.

Ken

On Mon, 23 Nov 1998, GahYan Diane Tsui wrote:

> i was trying the division operators but apparently / returns a floating
> point and \ returns an integer, but when i tried using the latter, it gave
> me some "unicode escape sequence" as the error message.  if that makes any
> sense to anyone, please let me know.  i think it has something to do with \
> being an ASCII character.  Let me try the int(expression) thing too.
> thanks.
> 
> [email-masked]
> 
>