6.096 Class Notes -
    Friday, October 10, 1997!: Events! 

(by Jennifer Chung)

2.5 handouts:
documentation project (plus printout of files listed on that page)
course notes (beware! text may be changed!)

Miscellaneous Information.

Today: Events, java.awt

The following lecture has been designed as a post-Calculator problem set discussion.
Let's review.
(before) Interactive Control Loop.


(after) Event driven Programming. (grovel)

(language digression4)

But now, let's focus on...

JAVA.AWT

keep in mind that this is assuming that at the top of all of the following classes, it says "import java.awt"...
(nutshell digression5)

okay, I lied. Back to Event-driven programming.

The idea?


And now, the infamous java.awt package.
WARNING!: THE NUTSHELL BOOK HAS '#' METHODS TO INDICATE THAT THEY DON'T WORK IN JAVA 1.1 (THEY'RE FROM 1.0)

(abstract class digression7)
To the end: Graphics and stuff.
An example of canvas at work.
public class RectCanvas extends java.awt.Canvas {
    Graphics g;
    g.drawRect(10, 10, 35, 15);       // magic numbers, but
                                      // should be constants

thus:
    public void paint( Graphics g ) {
        g.setColor( Color.pink );
        g.drawRect( 10, 10, 35, 15 );
    }
}
end of canvas definition.
and hence the original and the paint method get:

On Wednesday: how to handle other kinds of events (ie, mice)...


Digressions, Side Comments, Etc.

digression 1.
To communicate between objects, one utilizes method invocation.
go back

digression 2

go back

digression 3.
Laugh during class, darnit! [ to las ~ :D ]
go back

digression 4.
Java beans are for visual programs (VBasic, etc.) but constructing GUIs. They're centered around event-driven programs.
[notetaker's note: i have no idea what this means any more]
go back

digression 5.
(a shameless plug for Java in a Nutshell)
Perhaps now is the time to purchase (a new used car? a house?) a Java documentation-type book. One can find information in such books, relevant information, such as further information about java.awt in such texts as Java in a Nutshell; it is reminded, of course, that one may find said information in the form of documents on the web, too. But have something handy for those long lonely nights of coding. Recommended: the nutshell book. Buy it for the tiger cover! Keep it for the awt docs!
go back

digression 6.
What's a GUI? [pron: "goo-ey"] go back

digression 7.

  1. may have no-body methods.
       public void run;
    versus
       public void run{ };
    and then there's
      public abstract void run;
    
  2. can't make an instance of this [ie, one of those "new _____" things]
go back


Questions? E-mail me.

~/www/10oct97.html | jsmthng@mit.edu | revised October 14,1997!