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. */ // // Note only the Event and Panel classes are used // from the awt package. // import java.awt.Event; import java.awt.Panel; import java.awt.BorderLayout; import java.applet.Applet; import awtExt.* ; import sysExt.* ; /** * A test of Choice components. */ public class ChoiceTest extends Frame { Choice c1; Choice c2; public ChoiceTest() { try { setLayout(new BorderLayout(5, 5)); c1 = new Choice(this, "ChoiceCallback"); c1.addItem("one"); c1.addItem("two"); c1.addItem("three"); c1.addItem("four"); add("North", c1); c2 = new Choice(this, "ChoiceCallback"); c2.addItem("een"); c2.addItem("twee"); c2.addItem("drie"); c2.addItem("vier"); add("Center", c2); /** * API 1 - create a methodRef and bind it to Button later via * addActionCallback() **/ methodRef mr = Callback.newRef( this, "doPrint" ) ; Button PrintButton = new Button("print" ); PrintButton.addActionCallback( mr ) ; /** * API 2 - pass a methodRef to constructor of Button **/ Button SaveButton = new Button("Save", Callback.newRef( this, "doSave" )); /** * API 3 - Pass the target and string representation of method * to button. Button will internally create a methodRef. **/ Button CancelButton = new Button("Cancel",//button label this, //target of message "doCancel" );//message to send. Panel aLayout = new Panel() ; aLayout.add(SaveButton, -1); aLayout.add(PrintButton, -1); aLayout.add(CancelButton, -1); add( "South", aLayout ) ; resize( 150, 300 ) ; move(200, 100); pack(); show(); } catch( Exception e ) { System.out.println( "Exception..." ) ; e.printStackTrace(); } } /** * This method gets called back from the print button... **/ public void doPrint( CallbackInfo cbi ) { System.out.println( "PRINTING." ) ; }; /** * This method gets called back from the save button... **/ public void doSave( CallbackInfo cbi ) { System.out.println( "SAVING." ) ; }; /** * This method gets called back from the cancel button **/ public void doCancel( CallbackInfo cbi ) { System.out.println( "CANCELLING" ) ; }; /** * This method gets called back from the Choice button **/ public void ChoiceCallback( CallbackInfo cbi ) { System.out.println( "IN CHOICE: " + cbi.what ) ; } public static void main(String args[]) { ChoiceTest aChoiceTest = new ChoiceTest(); } }