Computer Science 1
Top Lectures Assignments Noticeboard

Graphical User Interfaces

Reading: The cucs package

The cucs GUI Class


  1. Introduction
  • Implementing a class for a GUI window
  • Implementing a constructor
  • Reacting to external events
  • Getting the GUI started and ending the program
  • Imports needed
  • The GUI class comes from the cucs package and the widgets come from the java.awt package. Thus both packages (or each class used from each package) must be imported:

          import cucs.*;
          import java.awt.*;
    You may wish to look at the entire program now.

  • An additional widget
  • One additional widget that is an extension of a TextField widget is a TextArea widget. A text area allows more than one row of text, and it has both vertical and horizontal scroll bars to allow for lines that are longer than the display area and for more lines than can be shown in the display area. The constructor for a TextArea specifies the number of rows and the number of characters shown on each row:

         TextArea ta;
    
         ta = new TextArea(10, 30);
    The above text area will initially be empty. To add text to what is already in the text area widget, the append message can be used:
        ta.append("A line of text.\n");
        ta.append(s + "\n");
    The above code would add the line "A line of text." and the line that is the value of String s to the text area. Note that a new line is started by appending the end-of-line character ("\n") at the end of the previous line.

  • Examples

  • Last modified: 10/14/99