HELP! * GREY=local LOCAL HTML version of Foils prepared July 10 1996

Foil 169 Actions associated with Components in AWT - II

From Basic Lectures on Java Language Applets Graphics Networking Trip to China and Icase Tutorial -- July 12-28 and June 10-13 96. by Geoffrey C. Fox * See also color IMAGE

Suppose we have a bunch of buttons in a particular Container saying Red, Green, Blue as we illustrated earlier. Then a good action method would be
public boolean action(Event evt, Object arg) {
if( evt.target instanceof Button)
  • changeColor((String) arg); // changeColor Supplied by the user processes color defined by text string used in defining buttons
return true; // tell runtime that this event fully processed
}
void changeColor(String bname) { // A suitable user routine to be called by above action
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 Tue Feb 18 1997