HELP! * YELLOW=global GREY=local Global HTML version of Foils prepared 4 February 97

Foil 15 Actions associated with Components in AWT - II

From Feb 3 Delivered Lecture for Course CPS616 -- Java Lecture 4 -- AWT Through I/O CPS616 spring 1997 -- Feb 3 1997. by Nancy McCracken * See also color IMAGE
Secs 123.8
Suppose we have a bunch of buttons in a particular Container saying Red, Green, Blue as we illustrated earlier. Then an action method would be
  • public boolean action(Event evt, Object arg) {
  • if( evt.target instanceof Button)
    • changeColor((String) arg);
    • // where changeColor is a method supplied by the user
  • return true; // tell runtime that this event fully processed
  • }
  • void changeColor(String bname) { // suitable user method
  • if( bname.equals("Red")) setBackground(Color.red);
    • else if (bname.equals("Green")) setBackground(Color.green);
    • else if (bname.equals("Blue")) setBackground(Color.blue);
    • else setBackground(Color.pink); // our favorite color
  • }


Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sun Feb 16 1997