home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / un2maiq4 / pjjava / src / pj / awt / textcanvas.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  2.6 KB  |  97 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.     Written by the Personal Journal developers of Dow Jones & Company, Inc.
  4.  
  5.     Dow Jones makes no representations or warranties about 
  6.     the suitability of this software, either express or 
  7.     implied, including but not limited to the implied warranties 
  8.     of merchantability, fitness for a particular purpose, 
  9.     or non-infringement.  Dow Jones will not be liable for 
  10.     any damages suffered by a user as a result of using, 
  11.     modifying or distributing this software or its derivatives.
  12.  
  13.  
  14.     @(#)TextCanvas.java   0.00 17-Jan-96
  15.  
  16.         A canvas that displays text.
  17.  
  18.     Authors:
  19.  
  20.         jlee        James Lee
  21.  
  22.     Version Ident:
  23.  
  24.         $Header$
  25.  
  26.     History:
  27.  
  28.         28-Mar-96    jlee        Initial creation
  29. ---------------------------------------------------------------------------*/
  30.  
  31. package pj.awt;
  32.  
  33. import pj.awt.PjFinals;
  34.  
  35. import java.awt.Canvas;
  36. import java.awt.Color;
  37. import java.awt.FontMetrics;
  38. import java.awt.Graphics;
  39. import java.lang.Integer;
  40. import java.util.Vector;
  41.  
  42. /**
  43.  * A canvas that displays text.
  44.  *
  45.  * @version    0.00 28-Mar-96
  46.  * @author     jlee
  47. */
  48. public class TextCanvas extends Canvas
  49.     {
  50.     // --- Instance variables
  51.     private Vector vText = new Vector();
  52.     private Vector vFontStyle = new Vector();
  53.  
  54.  
  55.     // --- Public constructor
  56.  
  57.     public void paint(Graphics g)
  58.         {
  59.         g.setColor( Color.black );
  60.         g.setFont( PjFinals.fntAboutBoxTextBold );
  61.  
  62.         FontMetrics fmBoxText = g.getFontMetrics();
  63.  
  64.         int nFontHeight = fmBoxText.getHeight();
  65.  
  66.         for ( int i = 0; i < vText.size(); i++ )
  67.             {
  68.             switch ( ((Integer)vFontStyle.elementAt(i)).intValue() )
  69.                 {
  70.                 case 0: //PLAIN
  71.                     g.setFont( PjFinals.fntAboutBoxTextPlain );
  72.                     break;
  73.                 case 1: //BOLD
  74.                     g.setFont( PjFinals.fntAboutBoxTextBold );
  75.                     break;
  76.                 case 2: //ITALIC
  77.                     g.setFont( PjFinals.fntAboutBoxTextItalic );
  78.                     break;
  79.                 default:
  80.                     g.setFont( PjFinals.fntAboutBoxTextPlain );
  81.                     break;
  82.                 }
  83.             g.drawString( (String)vText.elementAt(i), 4, (i + 1) * nFontHeight );
  84.             }
  85.         }
  86.  
  87.     public void addText( String str, int nFontStyle )
  88.         {
  89.         vText.addElement( str );
  90.         vFontStyle.addElement( new Integer( nFontStyle ) );
  91.         }
  92.  
  93.     // --- Private operations
  94.  
  95.     }//TextCanvas
  96.  
  97.