home *** CD-ROM | disk | FTP | other *** search
/ Learn Java Now / Learn_Java_Now_Microsoft_1996.iso / JavaNow / Code / Chap12 / HelloAuto2 / HelloAuto.java < prev    next >
Encoding:
Java Source  |  1996-06-17  |  3.1 KB  |  98 lines

  1. //******************************************************************************
  2. // HelloAuto.java:    Applet
  3. //
  4. //******************************************************************************
  5. import java.applet.*;
  6. import java.awt.*;
  7.  
  8. //==============================================================================
  9. // Main Class for applet HelloAuto
  10. //
  11. //==============================================================================
  12. public class HelloAuto extends Applet
  13. {
  14.     // user defined data
  15.     private int m_nInitCnt;
  16.     private int m_nStartCnt;
  17.     private int m_nStopCnt;
  18.     private int m_nDestroyCnt;
  19.  
  20.     // HelloAuto Class Constructor
  21.     //--------------------------------------------------------------------------
  22.     public HelloAuto()
  23.     {
  24.         m_nInitCnt = 0;
  25.         m_nStartCnt = 0;
  26.         m_nStopCnt = 0;
  27.         m_nDestroyCnt = 0;
  28.     }
  29.  
  30.     // APPLET INFO SUPPORT:
  31.     //        The getAppletInfo() method returns a string describing the applet's 
  32.     // author, copyright date, or miscellaneous information.
  33.     //--------------------------------------------------------------------------
  34.     public String getAppletInfo()
  35.     {
  36.         return "Name: HelloAuto\r\n" +
  37.                "Author: Stephen R. Davis\r\n" +
  38.                "Created for Learn Java Now (c)";
  39.     }
  40.  
  41.  
  42.     // The init() method is called by the AWT when an applet is first loaded or 
  43.     // reloaded.  Override this method to perform whatever initialization your 
  44.     // applet needs, such as initializing data structures, loading images or 
  45.     // fonts, creating frame windows, setting the layout manager, or adding UI 
  46.     // components.
  47.     //--------------------------------------------------------------------------
  48.     public void init()
  49.     {
  50.         resize(320, 240);
  51.  
  52.         m_nInitCnt++;
  53.     }
  54.  
  55.     // Place additional applet clean up code here.  destroy() is called when 
  56.     // when you applet is terminating and being unloaded.
  57.     //-------------------------------------------------------------------------
  58.     public void destroy()
  59.     {
  60.         m_nDestroyCnt++;
  61.     }
  62.  
  63.     // HelloAuto Paint Handler
  64.     //--------------------------------------------------------------------------
  65.     public void paint(Graphics g)
  66.     {
  67.         g.drawString("Hello, world", 0, 10);
  68.         g.drawString("Init count    = " + m_nInitCnt,    0, 20);
  69.         g.drawString("Start count   = " + m_nStartCnt,   0, 30);
  70.         g.drawString("Stop count    = " + m_nStopCnt,    0, 40);
  71.         g.drawString("Destroy count = " + m_nDestroyCnt, 0, 50);
  72.     }
  73.  
  74.     //        The start() method is called when the page containing the applet 
  75.     // first appears on the screen. The AppletWizard's initial implementation 
  76.     // of this method starts execution of the applet's thread.
  77.     //--------------------------------------------------------------------------
  78.     public void start()
  79.     {
  80.         m_nStartCnt++;
  81.     }
  82.     
  83.     //        The stop() method is called when the page containing the applet is 
  84.     // no longer on the screen. The AppletWizard's initial implementation of 
  85.     // this method stops execution of the applet's thread.
  86.     //--------------------------------------------------------------------------
  87.     public void stop()
  88.     {
  89.         m_nStopCnt++;
  90.     }
  91.  
  92.  
  93.  
  94.  
  95.     // TODO: Place additional applet Code here
  96.  
  97. }
  98.