home *** CD-ROM | disk | FTP | other *** search
/ Learn Java Now / Learn_Java_Now_Microsoft_1996.iso / JavaNow / Code / Chap14 / StaticMarquee / StaticMarquee.java < prev    next >
Encoding:
Java Source  |  1996-06-18  |  6.2 KB  |  184 lines

  1. //******************************************************************************
  2. // StaticMarquee.java:    Applet
  3. //
  4. //******************************************************************************
  5. import java.applet.*;
  6. import java.awt.*;
  7.  
  8. //==============================================================================
  9. // Main Class for applet StaticMarquee
  10. //
  11. //==============================================================================
  12. public class StaticMarquee extends Applet
  13. {
  14.     // PARAMETER SUPPORT:
  15.     //        Parameters allow an HTML author to pass information to the applet; 
  16.     // the HTML author specifies them using the <PARAM> tag within the <APPLET> 
  17.     // tag.  The following variables are used to store the values of the 
  18.     // parameters.
  19.     //--------------------------------------------------------------------------
  20.  
  21.     // Members for applet parameters
  22.     // <type>       <MemberVar>    = <Default Value>
  23.     //--------------------------------------------------------------------------
  24.     String m_string = "";
  25.     String m_font = "Courier";
  26.     String m_style = "PLAIN";
  27.     int m_size = 12;
  28.  
  29.     // parameter names. to change the name of a parameter,
  30.     // you need only make a single change. simply modify
  31.     // the value of the parameter string below.
  32.     //--------------------------------------------------------------------------
  33.     final String PARAM_string = "string";
  34.     final String PARAM_font = "font";
  35.     final String PARAM_style = "style";
  36.     final String PARAM_size = "size";
  37.  
  38.     // StaticMarquee Class Constructor
  39.     //--------------------------------------------------------------------------
  40.     public StaticMarquee()
  41.     {
  42.         // TODO: Add Constructor code here
  43.     }
  44.  
  45.     // StaticMarquee Class Destructor
  46.     //--------------------------------------------------------------------------
  47.     public void finalize()
  48.     {
  49.         // TODO: Add Destructor code here
  50.     }
  51.  
  52.     // APPLET INFO SUPPORT:
  53.     //        The getAppletInfo() method returns a string describing the applet's 
  54.     // author, copyright date, or miscellaneous information.
  55.     //--------------------------------------------------------------------------
  56.     public String getAppletInfo()
  57.     {
  58.         return "Name: StaticMarquee\r\n" +
  59.                "Author: Stephen R. Davis\r\n" +
  60.                "Created for Learn Java Now (c)";
  61.     }
  62.  
  63.     // PARAMETER SUPPORT
  64.     //        The getParameterInfo() method returns an array of strings describing 
  65.     // the parameters understood by this applet.
  66.     // 
  67.     // StaticMarquee Parameter Information:
  68.     //  { "Name", "Type", "Description" },
  69.     //--------------------------------------------------------------------------
  70.     public String[][] getParameterInfo()
  71.     {
  72.         String[][] info =
  73.         {
  74.             { PARAM_string, "String", "String to output in marquee" },
  75.             { PARAM_font, "String", "Font to use" },
  76.             { PARAM_style, "String", "PLAIN, BOLD, or ITALIC" },
  77.             { PARAM_size, "int", "Font size [pts]" },
  78.         };
  79.         return info;        
  80.     }
  81.  
  82.     // The init() method is called by the AWT when an applet is first loaded or 
  83.     // reloaded.  Override this method to perform whatever initialization your 
  84.     // applet needs, such as initializing data structures, loading images or 
  85.     // fonts, creating frame windows, setting the layout manager, or adding UI 
  86.     // components.
  87.     //--------------------------------------------------------------------------
  88.     public void init()
  89.     {
  90.         // PARAMETER SUPPORT
  91.         //        The following code retrieves the value of each parameter 
  92.         // specified with the <PARAM> tag and stores it in a member 
  93.         // variable.
  94.         //----------------------------------------------------------------------
  95.         String param;
  96.  
  97.         // string: String to output in marquee
  98.         //----------------------------------------------------------------------
  99.         param = getParameter(PARAM_string);
  100.         if (param != null)
  101.             m_string = param;
  102.  
  103.         // font: Font to use
  104.         //----------------------------------------------------------------------
  105.         param = getParameter(PARAM_font);
  106.         if (param != null)
  107.             m_font = param;
  108.  
  109.         // style: PLAIN, BOLD, or ITALIC
  110.         //----------------------------------------------------------------------
  111.         param = getParameter(PARAM_style);
  112.         if (param != null)
  113.             m_style = param;
  114.  
  115.         // size: Font size [pts]
  116.         //----------------------------------------------------------------------
  117.         param = getParameter(PARAM_size);
  118.         if (param != null)
  119.             m_size = Integer.parseInt(param);
  120.  
  121.         // resize(600, 80);
  122.  
  123.         // TODO: Place Addition Initialization code here
  124.         // create the font here based on the parameters entered
  125.         int nStyle = Font.PLAIN;
  126.         if (m_style.equalsIgnoreCase("BOLD"))
  127.         {
  128.             nStyle = Font.BOLD;
  129.         }
  130.         if (m_style.equalsIgnoreCase("ITALIC"))
  131.         {
  132.             nStyle = Font.ITALIC;
  133.         }
  134.  
  135.         Font font = new Font(m_font, nStyle, m_size);
  136.  
  137.         // now make this the font for this applet's window
  138.         setFont(font);
  139.  
  140.     }
  141.  
  142.     // Place additional applet clean up code here.  destroy() is called when 
  143.     // when you applet is terminating and being unloaded.
  144.     //-------------------------------------------------------------------------
  145.     public void destroy()
  146.     {
  147.         // TODO: Place applet cleanup code here
  148.     }
  149.  
  150.     // StaticMarquee Paint Handler
  151.     //--------------------------------------------------------------------------
  152.     public void paint(Graphics g)
  153.     {
  154.         // nVertOffset is calculated to center the string
  155.         // vertically in the window
  156.         int nVertOffset = size().height;
  157.         nVertOffset = (nVertOffset - m_size) / 2;
  158.         g.drawString(m_string, 5, nVertOffset + m_size);
  159.     }
  160.  
  161.     //        The start() method is called when the page containing the applet 
  162.     // first appears on the screen. The AppletWizard's initial implementation 
  163.     // of this method starts execution of the applet's thread.
  164.     //--------------------------------------------------------------------------
  165.     public void start()
  166.     {
  167.         // TODO: Place additional applet Start code here
  168.     }
  169.     
  170.     //        The stop() method is called when the page containing the applet is 
  171.     // no longer on the screen. The AppletWizard's initial implementation of 
  172.     // this method stops execution of the applet's thread.
  173.     //--------------------------------------------------------------------------
  174.     public void stop()
  175.     {
  176.     }
  177.  
  178.  
  179.  
  180.  
  181.     // TODO: Place additional applet Code here
  182.  
  183. }
  184.