package awtExtExamples ; /* * * Copyright (c) 1995 Sun Microsystems, Inc. All Rights Reserved. * * Permission to use, copy, modify, and distribute this software * and its documentation for NON-COMMERCIAL purposes and without * fee is hereby granted provided that this copyright notice * appears in all copies. Please refer to the file "copyright.html" * for further important copyright and licensing information. * * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ import java.awt.Panel; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.CardLayout; import sysExt.* ; import awtExt.* ; public class CardTest extends Frame { CardPanel cards; public CardTest() { try { setLayout(new BorderLayout()); add("Center", cards = new CardPanel()); Panel p = new Panel(); p.setLayout(new FlowLayout()); add("South", p); p.add(new awtExt.Button("first" , this, "buttonMethod" )); p.add(new awtExt.Button("next" , this, "buttonMethod" )); p.add(new awtExt.Button("previous" ,this, "buttonMethod" )); p.add(new awtExt.Button("last" , this, "buttonMethod" )); awtExt.Choice c = new awtExt.Choice(this, "choiceMethod" ); c.addItem("one"); c.addItem("two"); c.addItem("three"); c.addItem("four"); c.addItem("five"); p.add(c); move( 200, 200 ) ; show(); } catch( Exception e ) { e.printStackTrace() ; } ; } //-------------------------------------- // Call back method for choice object... // public void choiceMethod( awtExt.CallbackInfo cbi ) { ((CardLayout)cards.getLayout()).show(cards,(String)cbi.what); } //--------------------------------------- // Call back method for button object. The label // of the button is the method name to execute... // So create a methodRef from that and execute it!! // public void buttonMethod( awtExt.CallbackInfo cbi ) { try { /* ** Create a methodRef based on the button label... */ methodRef mr = methodRef.newRef( cards.getLayout(), //Class (String)cbi.what, //method Class.forName("java.awt.Container")// Container ); /* ** Execute that method.... */ mr.doAction( cards ); } catch( Exception e ) { e.printStackTrace() ; } } public static void main(String args[]) { CardTest cardTest = new CardTest(); } }