Held Tuesday, February 15, 2000
Today we consider how to build simple graphical applications in Java.
We will consider some basics, including windows, buttons, text fields,
- This Thursday's convocation is Mathematics 4,000 Years Ago
and will be given by Noyce Visiting Professor Richard Guy. I expect
that it will be a lot of fun.
- On Thursday afternoon, Pete Broadwell will be giving a talk about his
internship at IBM. I also expect that this talk will be a lot of fun.
- A few of you have asked about my grading policies on exams. They are not
the same as for homeworks. On exams, you start with 100 and I take off
for incorrect parts of your answers. (I also give a few points of extra
credit here and there when I see something particularly nice.)
- Even though I worked until 11 p.m. last night, I was not able to get your
homeworks graded. I hope to return them tomorrow morning.
- Don't forget to turn in project teams tomorrow.
- I'd appreciate it if you'd indicate the amount of time you spend on each
problem (or subproblem) of the exam.
- Are there other questions on exam 1?
- GUI basics
- Java's Abstract Windowing Toolkit (AWT)
- Primary components: Frames, TextFields, etc.
- Event handling
- Lab G2:
Java's Abstract Windowing Toolkit
- Preparatory reading of Lab G2
- Although many of the programs we've been writing are text-based,
most modern programs use a graphical user interface (GUI).
- Java's included toolkits for building GUIs since the early versions.
- Unfortunately, these toolkits have changed substantially as
Java evolved from 1.0 to 1.1 and from 1.1 to 1.2.
- We'll focus on the Abstract Windowing Toolkit (AWT) because it is supported
in Java 1.1 and Java 1.2.
- Java 1.2 add Swing, but Swing is not yet fully supported on our
HP/UX workstations. (It's also not supported on some other platforms,
which makes the AWT appropriate for many programs.)
- GUIs use an event-driven programming model. We might also
call this a reactive model.
- Rather than using an imperative model in which your
program says step-by-step what do do, reactive programs have
event handlers which basically say ``when this happens,
- You'll still need a
main method to create the objects
which supply these event handlers.
- As you might guess, GUIs have a number of components (menus,
buttons, text labels, etc.). In Java, each component is an object.
- We put components into windows and frames using the
- A layout determines how/where the components appear.
- Each component can have one or more listeners that respond
to the events that pertain to the object. (You should have read
something about this in chapter 1 of Java Plus Data Structures.)
- The rest of the details are in the lab.
- You will find that there are many different techniques for designing
GUI applications. I'll probably use a few different ones throughout
Do as much of G2.1 through
G2.4 as you can.
You should try to finish up the rest in the evening, although I will
understand if you cannot because of the amount of time you're devoting
to the exam.