[Current] [News] [Glance] [Search] [Instructions] [Links] [Handouts] [Project] [Outlines] [Labs] [Homeworks] [Quizzes] [Exams] [Examples] [EIJ] [API]
Back to Equality Testing. On to Lab: Java's AWT, Continued.
Held Tuesday, September 19, 2000
Summary
Today we move away from the basics of the Java language and start to consider how to build simple GUI (graphical user interface) applications with Java. We examine some basic issues in GUI construction, including windows, buttons, text fields, and events.
Notes
Overview
Component
main method to create the objects
which supply these event handlers.
Frame.
public class OurGUI
{
public static void main(String[] args) {
}
} // class OurGUI
import java.awt.Frame;
...
public static void main(String[] args) {
// Set up the primary window.
Frame window = new Frame("Our First GUI");
}
FlowLayout.
import java.awt.FlowLayout;
...
window.setLayout(new FlowLayout();
window.pack();
window.show();
WindowListeners
to listen to frames. You can extend WindowAdapter
for your initial listeners.
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public class QuitWhenClosed
extends WindowAdapter
{
public void windowClosing(WindowWEvent we) {
} // windowClosing(WindowEvent)
} // class QuitWhenClosed
import QuitWhenClosed;
...
public class OurGUI {
...
Frame window = new Frame(...);
QuitWhenClosed quitter = new QuitWhenClosed();
window.addWindowListener(quitter);
...
} // class OurGUI
public void windowClosing(WindowWEvent we) {
System.exit(0);
} // windowClosing(WindowEvent)
new ClassName(parameters) {
OverriddenMethods
}
WindowListener quitter =
new WindowAdapter() {
/**
* Quit the program when the user closes this window.
*/
public void windowClosing(WindowEvent we) {
System.exit(0);
} // windowClosing(WindowEvent)
} // the extended WindowAdapter
window.add(new WindowAdapter() { ... });
Are there questions on the readings?
Do lab G3, parts G3.1 and G3.2. I'd like you to finish this on your own if you can't finish it in class today.
Wednesday, 23 August 2000
Thursday, 24 August 2000
Tuesday, 19 September 2000
Back to Equality Testing. On to Lab: Java's AWT, Continued.
[Current] [News] [Glance] [Search] [Instructions] [Links] [Handouts] [Project] [Outlines] [Labs] [Homeworks] [Quizzes] [Exams] [Examples] [EIJ] [API]
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS152/2000F/Outlines/outline.15.html
Source text last modified Wed Oct 25 10:05:37 2000.
This page generated on Fri Oct 27 08:19:53 2000 by Siteweaver. Validate this page's HTML.
Contact our webmaster at rebelsky@grinnell.edu