home *** CD-ROM | disk | FTP | other *** search
/ Freesoft 1997 May / Freesoft_1997-05_cd.bin / recenz / PROGRAM / JAVADRAW / iavadraw301_inst.exe / data.z / TestAcme02Bean.java < prev    next >
Text File  |  1997-05-20  |  3KB  |  96 lines

  1. /*
  2.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software
  5.  * and its documentation for NON-COMMERCIAL purposes and without
  6.  * fee is hereby granted provided that this copyright notice
  7.  * appears in all copies. Please refer to the file "copyright.html"
  8.  * for further important copyright and licensing information.
  9.  *
  10.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  11.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  12.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  13.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  14.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  15.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  16.  */
  17. import java.awt.*;
  18. import java.applet.*;
  19.  
  20. public class TestAcme02Bean extends Applet
  21. {
  22.    String msgStr;
  23.    private Acme02Bean b;
  24.  
  25.    public void init()
  26.    {
  27.      b = new Acme02Bean();
  28.      add(b);
  29.       setFont(new Font("TimesRoman", Font.BOLD, 24));
  30.       msgStr = "Press any key...";
  31.       setForeground(Color.blue);
  32.       add(new Button("make action event"));
  33.       setSize(400,200);
  34.    }
  35.  
  36.    public void start()
  37.    {
  38.       requestFocus();
  39.    }
  40.  
  41.    public boolean keyDown(Event e,  int key)
  42.    {
  43.       msgStr = "\"" + (char)key + "\"" + " key pressed";
  44.       if ((char)key == 'q') {
  45.         System.exit(0);
  46.         System.out.println("Got a 'q'");
  47.       }
  48.       repaint();
  49.       return true;
  50.    }
  51.  
  52.    public boolean keyUp(Event e,  int key)
  53.    {
  54.       msgStr = "\"" + (char)key + "\"" + " key released";
  55.       repaint();
  56.       return true;
  57.    }
  58.  
  59.    public boolean gotFocus(Event e,  Object arg)
  60.    {
  61.       msgStr = "Got Focus";
  62.       if (arg!= null)
  63.          msgStr = msgStr + " arg: " + arg.toString();
  64.       repaint();
  65.       return true;
  66.    }
  67.  
  68.    public boolean lostFocus(Event e,  Object arg)
  69.    {
  70.       msgStr = "Lost Focus" ;
  71.       if (arg != null)
  72.          msgStr = msgStr + " arg: " + arg.toString();
  73.       repaint();
  74.       return true;
  75.    }
  76.  
  77.    public boolean action(Event e,  Object arg)
  78.    {
  79.       msgStr = "Action Event." ;
  80.       if (arg != null)
  81.          msgStr = msgStr + " Arg: " + arg.toString();
  82.       repaint();
  83.       return true;
  84.    }
  85.  
  86.    public void paint(Graphics g)
  87.    {
  88.       FontMetrics currFM = g.getFontMetrics();
  89.       g.drawString(msgStr, ( getSize().width -
  90.       currFM.stringWidth(msgStr)) / 2,
  91.       (getSize().height- currFM.getHeight())/ 2 +
  92.       currFM.getLeading() + currFM.getAscent());
  93.     }
  94.  
  95. }
  96.