/** EventDumper version 1.1, a demo applet for Java 1.1 events. Copyright (C) 1996-2000 Doyle B. Myers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA As a special exception, Doyle B. Myers gives permission to link this program with The Java platform and distribute the resulting executable, without including the source code for The Java platform in the source distribution. The phrase "The Java platform" specifically means the contents of all java.* packages as provided by Sun for either Commercial Use or under the Sun Community Source Code License. */ import java.awt.*; import java.applet.Applet; import java.util.*; import java.awt.*; import java.awt.event.*; public class EventDumper extends Applet { private static final int kWidth = 80; private TextArea mNotepad; public Container mControlContainer = new Panel(); public void init() { mControlContainer.setLayout( new GridLayout( 1, 4, 12, 12 ) ); add( mControlContainer ); mControlContainer.add( new Label( "Try these popular items! --->" ) ); mNotepad = new TextArea( 3, kWidth ); mNotepad.setText( "Type here!" ); add( mNotepad ); new KeyDumper( this ); new ContainerDumper( this ); new ActionDumper( this ); new AdjustmentDumper( this ); new ComponentDumper( this ); new FocusDumper( this ); new ItemDumper( this ); new MouseDumper( this ); new MouseMotionDumper( this ); new TextDumper( this ); new WindowDumper( this ); new PropertyDumper( this ); mNotepad.requestFocus(); repaint(); } // ----------------------------------------------------------------------- class ActionDumper extends TextField implements ActionListener { private String mTitle = "Action: "; private Button mButton = null; public ActionDumper( Applet inApplet) { super( "", kWidth ); mButton = new Button( "Test" ); mControlContainer.add( mButton ); mButton.addActionListener( this ); setText( mTitle ); setEditable( false ); inApplet.add( this ); } public void actionPerformed(ActionEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} } // ----------------------------------------------------------------------- class AdjustmentDumper extends TextField implements AdjustmentListener { private String mTitle = "Adjustment: "; private Scrollbar mBar = null; public AdjustmentDumper( Applet inApplet) { super( "", kWidth ); mBar = new Scrollbar( Scrollbar.HORIZONTAL, 0, 10, -100, 100 ); mControlContainer.add( mBar ); mBar.addAdjustmentListener( this ); setText( mTitle ); setEditable( false ); inApplet.add( this ); } public void adjustmentValueChanged(AdjustmentEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} } // ----------------------------------------------------------------------- class ComponentDumper extends TextField implements ComponentListener { private String mTitle = "Component: "; public ComponentDumper( Applet inApplet) { super( "", kWidth ); inApplet.addComponentListener( this ); setText( mTitle ); setEditable( false ); inApplet.add( this ); } public void componentResized(ComponentEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} public void componentMoved(ComponentEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} public void componentShown(ComponentEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} public void componentHidden(ComponentEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} } // ----------------------------------------------------------------------- class ContainerDumper extends TextField implements ContainerListener { private String mTitle = "Container: "; public ContainerDumper( Applet inApplet) { super( "", kWidth ); inApplet.addContainerListener( this ); setText( mTitle ); setEditable( false ); inApplet.add( this ); } public void componentAdded(ContainerEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} public void componentRemoved(ContainerEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} } // ----------------------------------------------------------------------- class FocusDumper extends TextField implements FocusListener { private String mTitle = "Focus: "; public FocusDumper( Applet inApplet) { super( "", kWidth ); mNotepad.addFocusListener( this ); setText( mTitle ); setEditable( false ); inApplet.add( this ); } public void focusGained(FocusEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} public void focusLost(FocusEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} } // ----------------------------------------------------------------------- class ItemDumper extends TextField implements ItemListener { private String mTitle = "Item: "; private Checkbox mCheckbox = null; public ItemDumper( Applet inApplet) { super( "", kWidth ); mCheckbox = new Checkbox( "Test" ); mControlContainer.add( mCheckbox ); mCheckbox.addItemListener( this ); setText( mTitle ); setEditable( false ); inApplet.add( this ); } public void itemStateChanged(ItemEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} } // ----------------------------------------------------------------------- class KeyDumper extends TextField implements KeyListener { private String mTitle = "Key: "; public KeyDumper( Applet inApplet) { super( "", kWidth ); inApplet.addKeyListener( this ); // listen to top mNotepad.addKeyListener( this ); // listen to notepad this.addKeyListener( this ); // listen to self setText( mTitle ); setEditable( false ); inApplet.add( this ); } public void keyTyped(KeyEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} public void keyPressed(KeyEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} public void keyReleased(KeyEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} } // ----------------------------------------------------------------------- class MouseDumper extends TextField implements MouseListener { private String mTitle = "Mouse: "; public MouseDumper( Applet inApplet) { super( "", kWidth ); inApplet.addMouseListener( this ); setText( mTitle ); setEditable( false ); inApplet.add( this ); } public void mouseClicked(MouseEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} public void mousePressed(MouseEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} public void mouseReleased(MouseEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} public void mouseEntered(MouseEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} public void mouseExited(MouseEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} } // ----------------------------------------------------------------------- class MouseMotionDumper extends TextField implements MouseMotionListener { private String mTitle = "MouseMotion: "; public MouseMotionDumper( Applet inApplet) { super( "", kWidth ); inApplet.addMouseMotionListener( this ); setText( mTitle ); setEditable( false ); inApplet.add( this ); } public void mouseDragged(MouseEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} public void mouseMoved(MouseEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} } // ----------------------------------------------------------------------- class TextDumper extends TextField implements TextListener { private String mTitle = "Text: "; public TextDumper( Applet inApplet) { super( "", kWidth ); mNotepad.addTextListener( this ); setText( mTitle ); setEditable( false ); inApplet.add( this ); } public void textValueChanged(TextEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} } // ----------------------------------------------------------------------- class WindowDumper extends TextField implements WindowListener { private String mTitle = "Window: "; public WindowDumper( Applet inApplet) { super( "", kWidth ); mTitle = "No Window"; int i = 0; for( Container c = inApplet; c != null; c = c.getParent() ) { if( c instanceof Window ) { ((Window)c).addWindowListener( this ); mTitle = "Window[" + i + "]"; break; } i++; } //inApplet.addWindowListener( this ); setText( mTitle ); setEditable( false ); inApplet.add( this ); } public void windowOpened(WindowEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} public void windowClosing(WindowEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} public void windowClosed(WindowEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} public void windowIconified(WindowEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} public void windowDeiconified(WindowEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} public void windowActivated(WindowEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} public void windowDeactivated(WindowEvent e) {setText( mTitle + e ); System.out.println( mTitle + e );} } // ----------------------------------------------------------------------- class PropertyDumper extends TextArea { public PropertyDumper( Applet inApplet) { super( 8, kWidth ); setText( "System Properties:" ); this.addProperty( "os.name" ); this.addProperty( "java.version" ); this.addProperty( "java.vendor" ); this.addProperty( "java.vendor.url" ); this.addProperty( "java.home" ); this.addProperty( "java.class.version" ); this.addProperty( "java.class.path" ); this.addProperty( "os.arch" ); this.addProperty( "os.version" ); this.addProperty( "file.separator" ); this.addCharToIntProperty( "line.separator" ); this.addProperty( "user.name" ); this.addProperty( "user.home" ); this.addProperty( "user.dir" ); setEditable( false ); inApplet.add( this ); } private void addProperty( String inName ) { String theValue; this.append( "\n " + inName + " = " ); try { theValue = System.getProperty( inName ); } catch( Exception e ) { theValue = "[exception: " + e + "]"; } this.append( theValue ); } private void addCharToIntProperty( String inName ) { String theValue; this.append( "\n " + inName + " = " ); try { theValue = System.getProperty( inName ); int i = (int)theValue.charAt( 0 ); theValue = i + " (decimal)"; } catch( Exception e ) { theValue = "[exception: " + e + "]"; } this.append( theValue ); } } }