Basic HTML version of Foils prepared May 12 1996

Foil 119 Actions associated with Components in AWT - II

From CRPC Lectures on Java Language Applets Graphics CRPC Annual Meeting Tutorial -- May 14,1996. by Geoffrey C. Fox


1 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
2 public boolean action(Event evt, Object arg) {
3 if( evt.target instanceof Button)
  • changeColor((String) arg); // changeColor Supplied by the user processes color defined by text string used in defining buttons
4 return true; // tell runtime that this event fully processed
5 }
6 void changeColor(String bname) { // A suitable user routine to be called by above action
7 if( bname.equals("Red")) setBackground(Color.red);
8 else if (bname.equals("Green")) setBackground(Color.green);
9 else if (bname.equals("Blue")) setBackground(Color.blue);
10 else setBackground(Color.pink); // our favorite color
11 }

in Table To:


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 Dec 14 1997