Experiments in Java


Problems for Session G3: Java's Abstract Windowing Toolkit, Continued

Problem G3-A: Observing the user

Read the documentation for the TextField class and determine what events are sent when the user types, what kind of listener can react to those events, and how the listener can react. Write a short summary that your classmates should be able to understand and use.

Problem G3-B: Capitalization

Using your answer from Problem G3-A, write a simple GUI that observes what the user types and capitalizes every letter typed.

Problem G3-C: Passwords

Using your answer from Problem G3-A, write a simple GUI that reads in a password typed in a text field, putting some special symbol in the field in place of each character typed.

Problem G3-D: Setting the size of text fields

Java provides a setSize method for text fields as well as for other components. Read and report on the use and abuse of this method. Can you use it to create a blank field, as we needed in Experiment G3.2?

Problem G3-E: Beginning a real calculator

Build a new graphical user interface class, Calculator, which displays eleven buttons corresponding to the ten decimal digits (0, 1, ..., 9) and clear. Your class should also display a field. When the user clicks on a digit, you should add it to the end of the field.

Problem G3-F: Adding calculation

Extend your Calculator class to support an add and equals button. The add button should remember the current value in the display field and clear that field. The equals button should add the contents of the display field and added it to the remembered value. If this seems odd to you, consider the interface for a typical desktop calculator.


Copyright (c) 1998 Samuel A. Rebelsky. All rights reserved.

Source text last modified Mon Oct 25 23:29:32 1999.

This page generated on Tue Oct 26 15:38:01 1999 by Siteweaver.

Contact our webmaster at rebelsky@math.grin.edu