     5 

     

      Java  ,   " 
" (World Wide Web  WWW),       
Java.   WWW       
 , ..   ,   Java -- 
  .  ,   
-       
    Java. 
       ,      Java   
,    .    
,    ,      , 
         WWW. 
          Java-,  
Java        
.   Java    ,  ,    
 ,      , 
  . 
    ,         
  .       
.         
   .      
.     ,    
 ,  .       
       Java.  , 
  ,     .  Java 
  ,     
.           
  . 

    V. 
    145 

        

     Java         
  (display surface).     
. ,     ,     
  .        
,    . 
             
 .        .  
        
      . 
    ,     ,    
 .          . 
    .     
         
 ,     .  
,  ,     ,  , 
            
 . 
       ,     , 
           "', 
  .       , 
     .      
          
 . (  ,    .) 
             ,  
,        ( API  
Application Programming Interface).     
   - . ,   
        ,   
 . ,   ? 
      Graphics      API,   
    . (,   
 API,          .)  
  Graphics ,  ,     
.           
 Graphics,     .  
        
Graphics,    .    , 
  ,  API  Graphics,   
   .       
    ,      . 

    146	Visual J++:   

     . 5.1 ,      
    API  Graphics. 

         


    . 5.1. API  Graphics      


       Graphics 

             
- ,         
.         , 
   .      
   . 
          3,      
  update()/paint()  Component.   
 Java    .     , 
     ,   
  ,      
  .   Java ,    
   ( ""),     Graphics, 
    ,    
  updateQ   .   
update() : 

    public v**^ update(Graphics g) 

              Graphics.  
       
 . 
      ,        
      

     5.  147 

. , ,     
 , ,     ".   
    .       
    ,     
 . ,   ,   
(invalid), ,   . 
       ,    
updateQ .   ,    
  . 
       ,   ,    
    ,      
 ,   repaint().    
""  Java        
  updateQ. 
       updateQ   paint() .   
   paint(),    updateQ.  Java 
  paintQ ,       updateQ.  
       ,      
  updateQ,    paintQ,   
   . 
     ,     Graphics,   
  ,     paint()  
( ),        
, ^^cjj^suiju^ffijebj^oj}^^ repaintQ. 

      Graphics 

      Graphics    ,  
     .    
   , , , , 
,        
 (  ,   ,  
  ).     
,      . 
       Graphics     , 
,    . ,    
Graphics     (current color),   
^  .   ,     
 .       
  .         
   .       
     ,   
    Graphics. 

    148	Visual J++:   

        ^^^  Graphics  
  .       ,   
      Graphics. 
    
    
          ______________________ 
    Surface	 ,     Graphics. 
       .  
          . 
    Current color	,      
    . 
    Clipping rectangle	 ,     
    "  Graphics.       . 
    Current font	,       
.    . 
    Painting mode	 paint  XOR.      
      .   
 XOR         
,   . 
    Origin	.    .   
(0,0)       ,     
. 

      

        ,    Graphics  
 - (   )   
.  , , ,    
     . 
      Java      Color.   
  ,     , ..  
  RGB. 
        Color    ,  
     Color  : 

    Color  col^rRed =  new Color (255,   0,   0);   //   . 

         , ,  
  16  .     
,   .  -  , 
     .      
32-       RGB. 

     5.  149 

         OxOOrrggbb.     
   ,    ,    
 .      (alpha)   
,      Java   .   
 32-     : 

    Color colorYellow = new Color(OxOOFFOOOO) /* . */ | 
    OxOOOOFFOO /* . */); 

        ,     
   Color   getRedQ, getGreenQ  getBlueQ 
 Color. _ RGB()  Color  32-   
    . 
      Color    ,   public.  
 ,    : , , 
, , , , ,   ..    
       : 

    Color myRedRef = Color.red; Color myWhiteRef = Color.white; 

             Graphics.  
getColorQ  Graphics    ,   
setColorQ     .    
  paintQ   .    
     ,  ,  
  : 

    public void paint(Graphics g) { //   . Color 
colorCurrent = g.getColor(); 
    //  ,   . 
    Color colorLighter = new Color(colorCurrent.getRed() + 5, 
    colorCurrent.getGreen() + 5, 
    colorCurrent.getBlue() + 5)); 


      

           .  
^ ,      ,  
 . 
            . 
 paintQ     Graphics,   
.          , 
   .  

    150	Visual J++:   

,   paintQ       
,      Frame     
  .      . 
    ,    ,  ,  
,     .   
  -   ,    
.         (. 5.2). 

     
    , 
     
     
      
     
      

    . 5.2.       ,   
,  

          update()/paint()  
    .  , ,  ,  
   .    
   ,    . 5.3.   
         
update()/paint(),      .  
 .  ,      
 ,      -   
      ! "^!~ 

     5.  151 


    I   1 
       2 
     2 
     1:        

    . 5.3.          

     getClipRectQ . Graphics    Rectangle,  
  ,      . 
    . 
     setClipRectQ  Graphics     
    Graphics.  ,   
   ,    .    
    .       , 
       .   
       Graphics, 
  paintQ,  ,      
    .    
   setClipRectQ     
    ^   setClipRectQ.  . 
5.4 ,    . 

    1      
    2   setClipRectang!e()   :        
    :3	 ,    
    ;	  ,  
    :	    

    . 5.4.       


    152 Visual J++:   

          : 
  ,     . , 
,       .  
     ,     
,        . 
  ,   .  ,   
 ,   : 

    public  void paint(Graphics  g) { Dimension   size   =   sizeO; 
    //               10   , //   
     5   . 
    for(int  col  =  5;   coloize .width;   col+=10) g.drawLine(   /*   , 
  */   col,   0, 
    /*     */  col,   size.height); 
    //      10 , //   5 . 
    for(int row = 5; row<size.height; row+=10) g.drawLine( /*   */ 0, row, 
    /*   */ size.width, row); } 

     .         
,        drawLine()  
.     ,    
":

    public void paint(Graphics g) {   -	.         , 
    Dimension size = size ();**	-'I  (AC 1^1^^''1^^ 
    Rectangle rectClip^= g.cjetClipRect () ;	IfajQ <A?/?f $ fr{# */%? 
    //      10  //  
 .	"~ for (int col=( (rectClip.x+4)/10)*10 + 5; 
    col < rectClTp.x+rectClip.width; col+=10) g drawLine ( /*   */ col, 
0,	n  N"""'' /*   */ col, size.height ); ^ 
    //      10  
    //   . 
    for (int row=((rectClip.y+4) /10) *10+5; 
    row<rectClip.y+rectClip.width; row+=10) g^urawLine( /*   */ 0, row, 
    /*   */ size.width, row); 


     5. 	153 


      

            , 
  .        Graphics 
   . 
      ?        
. ,  Courier      
      : 

    The Courier typeface looks like this. 

          .    
,    .      
  ,      .  , 
       , 
   .    1/72 . 
-        
   Java  ,     . 
, ,      Windows,    
  ,          
,     .     ,  
 Java      ,    Windows SDK  
MFC- Visual C++! 

      

      ,     .  . 5.5  
  .        
      (  ). 

      < 
    ^ r^iir^_Ihe.iquickiif6wrLiQxIirZ_~________~_ 
    Heightp - -JJ?!^ent-^5- ______!_J._________________________________
    ________ |_ .Leadi ng_ <=_ _________________________________________ 
    Jumped over the lasy programmer. 
    < 

    Puc. 5.5.        : 


    MeTWifta       

    Ascent	 ( )       
  .  ,   , t  h, ,  
  , . 

    154	Visual J++:   

           

    Descent	 ( )       
  .  ,  q, j, g,   
 . 
    Leading	   .   . 
    Height      . 

             , 
-   ,      
 .     Java   FontMetrics,   
Font.   FontMetrics      
;         Graphics,  
    . 
            Graphics  
  . ,       , 
      .       
    ,         
           Graphics. 
   FontMetrics      
   Graphics. 
     getFontMetricsQ  Graphics    , 
     .  , 
  FontMetrics   ( ) , 
    Graphics,     . 
      FontMetrics       
 .  getAscentQ      
.  getDescentQ      . 
 GertLeadingQ       
,    ,     
,    .    
     .  getHeightQ   
,   getAscendQ, getDescendQ  getLeadingQ,   
,       .  
charWidthQ   ( )   .  
stringWidth()      .   
  ,     String   
      (charWidthQ)    
(byteWidth()). ,  getWidths()   ,   256 
 ,      . 
      ,    FontMetrics  
 ,      .    

     5. 	155 

      ,  "lineX".    
   ,    ,   
FontMetrics.    ,     
,     ,      .  
. 5.6          
     lineX.      
Visual J++          JAVA , 
   ,      . 
   HTML-        
<APPLET>    Debug   Settings,  
       Visual J++. 

    import Java.applet...*; 'import java.awt.*; 
    public class FontMetricsApplet extends Applet { String!] m_astrLines;	""" 
    public void initO ( int cLines; for (cLines=0; null != 
getParameter("line"+cLines); cLines++); 
    m_astrLines = new String[cLines]; for(int ii=0; ii<cLines; ii++) 
    m__astrLines[ii] = getParameter("line"+ii); 
    }	, ^" 
    public void paint(Graphics g) ( 
    FontMetrics fm = g.getFontMetrics() ; Dimension size = sizef); 
    for (int ii=0; ii<m astrLines . lencjtji; ii++) { int ex = 
fm.stringWidth(m_astrLines[ii]); g.setColor(getForeground() ) ; if(ex >= size.width) 
    g.setColor(Color.red); g.drawstring(m_strLines[ii], 5, 
    "fm.getHeight()* (ii + 1))) ; 


    156	Visual J++:   


    . 5.6.   Font Metrics 

        . 5.6    HTML-: 

    <HTML> 
    <HEAD> 
    <TITLE>FontMetricsApplet Example</TITLE> 
    </HEAD> 
    <BODY> 
    <Hl>FontMetricsApplet Example</Hl> 
    <HR> 
    <APPLETCODE=" FontMetricsApplet.class" WIDTH="400" Height="300"> 
    <PARAM NA^E="lineO" VALUE="This is the first'"llnew> "  """ 
    <PARAM NAME="linel" VALUE="The quick brown fox"> 
    <PARAM NAME="line2" VALUE="jumped over the lazy long line of text 
    that runs on and on and on and on"> <PARAM NAME="line3" VALUE=""> 
    <PARAM NAME=*line4" VALUE="This example demonstrates how"> <PARAM 
NAME="line5" VALUE="to use the FontMetrics"> </APPLET? 
    "*%.. 
    </BODY> </HTML> 


     5.  157 


      

         ,     . 
   italic ()  bold ().     Java 
    .      
Font.ITALIC  Font.BOLD  Font,     
      . 
              
  Font    . 

     

      ,         
.     Courier     
,     .  ,    
     Courier   ,  
    Java. 
      Toolkit,    AWT,  ,   
  ,    .   
  getFontListQ    .     
    ,   .   
,     : 

    import java.awt.*; 
    public class ListFonts { 
    public static void main(String astrArgs[]) { 
    String astrFonts[] = Toolkit.getDefaultToolkit() .getFontList(); 
    for(int ii=0; ii<astrFonts.length; ii + + ) 
    System.out.println("Font" + ii + ": " + astrFonts[ii]); 


      

        ,      
    Java.   Font   
:  ,   (  ,   
    )   .     
  Courier    10    Italic: 
    Font   f  =*^hew  Font("Courier",   Font.ITALICS,    10); 
     setFont()  Graphics    Font.  
^      Graphics,   
           
 . 
      ,          
 .  FontGallery   

    158	Visual J++:   

  TabbedPanel,    3,    
.     ,    WWW    
   Visual J++ Handbook.     
      3   ,   
          
   ,    .  
  TabbedPanel    ,      
   ,   .       
        ,   
.  . 5.7    . 

    . 5.7.   FontGallery 

    import  j atra . awt. * ; import  Java.applet.*; 
    * class  FontDisplayPanel  extends   Panel   { 
    Font  m_font; 
    Font m_fdtitltal; 
    Font m_fontBold; 
    Font^m_fontBoldItal; 
    privatlS,String m_strSampleText; 
    public FontDisplayPanel (Font f, String s) { m_font = f; 
    m_fontltal = new Font(f.getName(), ~~      f.getStyleO I Font.ITALIC, f.getSizeO) 
    w 


     5.  159 

    m_fontBold = new Font(f.getName(), 
    f.getStyleO I Font. BOLD, f.getSize()); m_fontBoldltal = new Font(f.getName(), 
    ~ f.getStyle()| Font.BOLD | Font.ITALIC,f.getSize()); m_strSampleText = s; } 
    public void paint(Graphics g) { //  , g.setFont(m_font); 
    //   . 
    int  = g.getFontMetrics().getHeight(); 
    //     , , //    , g.drawstring(m_strSampleText, 5, ); 
    setFont(m_fontltal); 
    .drawstring(m_strSampleText, 5, cy*2); 
    setFont(m_fontBold); 
    g.drawstring(m_strSampleText, 5, cy*3); 
    setFont(m_fontBoldltal); 
    g.drawstring(m_strSampleText, 5, cy*4); 
    public class FontGallery extends Applet { public void init() { TabbedPanel tp; 
    //   TabbedPanel. 
    setLayout(new BorderLayout()); 
    add("Center", tp = new TabbedPanel()); 
    //   .   
    // (-bold, -italics)    . 
    //    . 
    String[] astrFonts = Toolkit.getDefaultToolkit().getFontList(); 
    for (int ii=0; ii<astrFonts.length; ii + + ) ( 
    Font f = new Font(astrFonts[ii], Font.PLAIN, 10); ^    
tp.addTab(astrFonts[ii], new Button(astrFonts[ii]), 
    newFontDisplayPanel(f, "The slow gray fox sneezed.")); 


      

       . ,   ,  
 ^ (paint mode). ,  ,  XOR-. 

    16 Visual J++:   

              
 Graphics     . ,  
  (,       
)      ,  , 
    .       
 ,         .
         Graphics     
.   : "    ?" .  
  ,     ""^" 
     XOR-    .      
    .   , ^ , 
    Graphics     XOR,  
 ,       .   
      XOR,   
   32-       RGB. 
    XOR-        
,       . , 
           
 -  . ,    , 
  ,    .      
,      _   ?  
    . 
          XOR-.  _  
  ,    ,    .  
. 5.8   . 

    . 5.8.  XOR-     


     5.  161 

         : 

    import java.awt.*; import Java.applet.*; import java.net.*; 
    public class SelectionRect extends Applet { Rectangle m_rectSelection; 
Image m_img; 
    public void init() { 
    // ,   "image" . 
    try { 
    m_img = getlmage(new URL(getDocumentBase().toStringO + 
    getParameter("image"))); m_rectSelection = null; 
    } catch(HalformedURLException e) { 
    /*   */} 
    //   update(),    //  
  , public void update () { paint(g); 
    public void paint(Graphics g) { 
    //  .  ,  //    
. g.drawlmage(m_img, , , this); g.setPaintMode(); 
    //    ,   
    //   XOR-. 
    if(null != m_rectSelection) { 
    Color colorAlt = new Color(-getForeground().getRGB()) 
    g.setXORMode(colorAlt); 
    g.drawRect(m_rectSelection.x, m_rectSelection.y, 
    m rectSelection.width, m_rectSelection.height); 
    7 
    *N* 
          . 
    :*"* ***** 
    v  public boolean mouseDown(Event evt, int x, int y) { m_rectSelection = 
new Rectangle(x, y, 0, 0); repaint(); return true; 


    162 Visual J++:   


    public boolean mouseUp(Event evt, int x, int y) { m_rectSelection = null; 
repaint(); return true; 
    public boolean mouseDrag(Event evt, int x, int y) ( 
    m_rectSelection .width + = x - m_rect_Selection . x; 
    m_ rectSelection.height +=  - m_rectSelection.; 
    repaint(); 
    return true; } 


      

      Graphics  ,   public,   
   , ,  , 
,  , ,  , , 
,  .        
     Graphics     
. ,       
     Graphics.    
     .   
     .     
,      . 

      

            
 .  Java,   ,   
drawLineQ  Graphics.       , 
..          .   
 : 

    public void paint (Graphics g) { 
    //          
    // . 
    g.drawLine(0,   0,   size() .width-1,   size() .height-1); 
    >	% 


      

         ,   
Graphics     ,  . 

     5.  163 

     , -,  ,      
 1^?,  ,   
  . 
          drawRectQ  
Graphics.    , ,    .  
fillRectQ        
    Graphics. ,    , 
   ,     
 : 


    public class MyCanvas extends Canvas ( 
    public void paint(Graphics g) ( 
    Rectangle rectBounds = bounds(); 
    //     10 , //   
   . rectBounds 
^jrowJMath.max(-size().width/2, -10), Math.max (-size() .height/2, -10)); 
    //  . 
    g.fillRect(rectBounds.x, rectBounds.y, rectBounds.width, rect.Bounds.height); 


      

    ,   ,    . 
   drawPolygon()  fiHPolygon()    - 
 Y-   : 

    int aXCoords| int aYCoords[ 
    = {10, 50, 50, 15) = (10, 15, 50, 50} 
    .drawPolygon(aXCoords, aYCoords, 4); 

     ,        
^_  , _  ^]_. 
      AWT   Polygon,      
 .    drawPoly-gon^yt 
fillPolygon()  Graphics   ,    
,       Polygon.  
 Polygon    .  addPointQ 
 Polygon  ,  ^    
.         
     

    164 Visual J++:   

    .         
,    . 

    import  java.awt.*; 
    import Java.applet.Applet; 
    public class PolygonDrawer extends Applet { int x[] = [0, 10, 15); int y[] 
= [0, 10, 15); Polygon m_poly = new Polygon(x, y, 3) ; 
    public void paint(Graphics g) { 
    //   . 
    g.fillPolygon(m_poly) ; } 
    //        //  , 
public boolean mouseDown(Event evt, int x, int y) { 
    m_poly.addPoint(x, y); 
    repaint (); 
    return true; } 

     . 5.9 ,  ,   Java   
,    .  , , 
   ;*    ,  
  .    "-". 

    . 5.9. ,    Graphics 


     5.  165 

      Polygon     . 
-,       X  Y   . 
         X  
  Y. -,   Polygon   , 
   .  getBound-ingBoxQ  Polygon 
   ,  .  
insideQ  Polygon   true,     
 .   "-" , 
     fillPolygonQ  Graphics, 
   inside()   ,     
    . 
           Polygon.  ,  
   move()     ,    
Polygon.          
   X  Y.     rotateQ  
scaleQ.    Polygon  npoints, xpointsf]  ypointsf]  
  ,      
    ,      
  move(): 

    class SuperPolygon extends Polygon { 
    public SuperPolygon(int xpoints[], int ypoints[],int npoints) ( 
    super(xpoints, ypoints, npoints); } 
    public void move(int dx, int dy) { 
    for(int ii=0; ii<npoints; ii-n-) { xpoints[ii] += dx; ypoints[ii] += dy; 


      

       drawOvalQ  fillOvalQ  Graphics   
  .      X  Y.  ,  
  ,      
. -   ,       
        , .. 
  "". 
    Tfplj      .  
   ,    .  . 5.10 
     ,    , 
 : 

    166 Visual J++:   


    public void paint(Graphics g) ( 
    Rectangle r = new Rectangle(10, 10, 50, 100) g.setXORMode(Color.red) ; 
    g.fillRect(r.x, r.y, r.width, r.height); g.drawOval(r.x, r.y, r.width, r.height); 


    . 5.10.      


       

       .  drawArcQ  fillArcQ  Graphics 
    ,    drawOvalQ  fillOvalQ.  
 ,     , 
        . (   
.)     2,    ,   
     . 
         ,  
    .      
,     . ,  
        ,  
  . 
      drawArc()  fillArc()     
: * "*, 

    public void drawArc(int x, int , int width, int height, 
    //  . 
    double startAngle)""double arcDistanceT?' public void fillArctint x, int 
y, int width, int height, 
    //  , double startAngle, double arcDistance); 


     5.  167 


      

       drawImageQ  Graphics    
   ,     Graphics 
        
    bitblting ('bit billing")  biting. 
(      "bit block transferring"  
  .)      
ImageCanvas.    minimumSize()  prefferdSizeQ 
  ,  : 

    import  java.awt.*; 
    public class ImageCanvas extends Canvas { private Image m_img; 
    public ImageCanvas (Image img) { m img = img; 
    public Dimension preferredSize() { 
    return new Dimension(m_img.getWidth(this) , m_img.getHeight(this)); } 
    public Dimension minimumSize() { 
    return preferredSize(); } 
    public void paint(Graphics g) { 
    g.drawlmage(m_img, 0, 0, this); 
    } 

      drawImageQ  Graphics   .   
 : ,   ,   X- 
Y-     ,    
 Graphics,      . 
         Image Observer.  
         
Visual J++.     .    
  Internet.   ,  ,  
    GIF  JPG,    . 
Java   .    ImageObserver 
~6  . ,    
 ImageCanvas   getWidth()  getHeight() miacca*!4mage  
     .     
         (  
      Internet),     
 ImageObserver.     ,  
ImageObserver    . ,     
   

    168 Visual J++:   

 ,   ImageObsejyerjjjaaojJSByeTCH.  Component 
 "187^  ImageCanvas ( 
-ɸ^   IrnageObserver. 

     

            
   " ",    
  .       
 ,  (, Pinball  , 
   ), ,   
     . 
     Visual ]++    ,   Sun.  
. 5.11, 5.12  5.13     Animator, 
GraphLayout  MoleculeViewer.       
 ,     . 

    . 5.11.  Animator 


     5.  169 


    . 5.12.  GraphLayout 

    . 5.13.  Molecule Viewer 


    170 Visual J++:   

       Java  .    _ 
,        . 
    ,   _ Animator  
Sun.          
      . , 
             
              .  
Animator      ,   
     . 

      :  Animator 

     Animator         
    .  
^_-,!,1 .  ( 0  N), , 
    , ,   
  ,  ,     
 .        
 Animator,    HREF (    
        ,),    
  (       
   ). ,     
,          . 
        Animator  Info Viewer   
.        : 
    1.    Visual J++.       Close 
Workspace  File,       InfoViewer. 
    2.     Samples     Sun Samples 
     Animator.     , 
     .  ,   
 ,     MSDEVtSAMPLES\SUNSAMPLES\ANIMATOR. 
    3.         Open Workspace  File 
 .    Open File ,    
.       
MSDEV\SAM-PLES\S4JNSAMPLES\ANIMATOR,     ,  
   Animator. 
         Animator.  : Animator, 
Description Frame, ParseException.        
.    ,    
Animator    . 

     5.  171 

      Animator       
 .           
    .     
    : 

    public class Animator extends Applet implements Runnable { Thread engine; 
int framenum = -1; 
    //   init()    , 
    //      ,   
    //    . 
    public void init() { 
    //   ,    
    //  . 
    //     ,   
    // . 
    } 
    //   start()     
    // engine. 
    public void start (} { 
    engine = new Thread(this); 
    engine.start (); 
    //   stop()      // engine.  
     , public void stop(} { engine = null; 
    //  run()    engine. //     
  . public void run() ( 
         engine. 
         ,  . 
          ,  
      engine { 
        framenum  1 
    repaint(); 
          
    //  paint()      // framenum. 
public void paint(Graphics g) ( 
    if(framenum >= 0)      //    -1   
  framenum  ,    . 


    172 Visual J++:   

          : 
         initQ     ,   
 . 
    	 startQ    . 
    	 stop()     
    	 paintQ    . 
         (),   ,    
   . 
           Animator   
 ClassView Visual J++,  ,       
.          
  .  ,   Animator   
 .     initQ   
 ,   init() ,    
  :  parselmagesQ   
,   ;  parseDurations()  
  ;  parseSoundsQ    
    . .  initQ  ,   
 ,         
,      . , 
   -     
 (initQ, startQ, stop(), paintQ  runQ). 

      

          ,   
       Java.  Java 
_,       
.  updated    paintQ   
_,   .     ypdateQ,  
     . 
      ' ,  updateQ   
 : 

    public voici, update (Graphics g) { paint(g); 
      
    "%_ 

     Animator        , 
  ._, ,   .     
  (,    Space Invaders,   
        )? 
      

     5.  173 

 .         
 ,       
   " ". 
             
    Animator.     
        
       .     
      .     
   ,       . 
   ,     
,   . 
         ,    . 
  runFrameGeneration()    . 
          
   .   ,    
    .     
    (  ),     
.      ,   
  ,          
 . 
         ,    
   .     
    ,   ,  - 
 . .     ,  
      ,       
.           .	-...-_-.-.-~.~. 
       ,      . 
        ,     
 .        
,     N .  ,  
  (N+\)-n ,    ,   
    .  ,      
 ./V  . 

       Graphics,      

          :    
   Graphics,     
.    ,  . 
    1.       .     
    createlmage(),    
   . 

    Image img2blBuffer = createlmage(width, height); 


    174 Visual J++:   

    2.  ^^11..__    getGraphicsQ  Image: 

    Graphics g2blBuffer = img2blBuffer.getGraphics (); 

           .  
      ,   .  
     ,   . 
      , ,     
-      ( 
    ).    
 ()   ;  initQ, stopQ  paintQ    
 . 

    public class MyAnimator extends Applet implements Runnable { Vector 
m_vectFrames = new Vector(); Thread m_threadAnimator; Thread 
m_threadFrameGenerator; Image m_imgNextFrame; 
    //  init()   . 
    //  start ()      . 
    //  stop()     . 
    //  paint()     // m_vectFrames  
 . 
    //  run () ,   , //  
 , public void run() ( 
    if(Thread.currentThread() == m_threadAnimator) 
    runAnimator(); if(Thread.currentThread() == m_threadFrameGenerator) 
    runGenerator (); } 
    //  runAnimator()    Animator, public void 
runAnimator() { 
       == m_threadAnimator 
    "   m_vectFrames     ,  *~~7 
            ^      
m_imgNextFrames.	J "^S,  repaint () 
       . 
    public void runFrameGenerator() { 
       ,  


     5. 	175 

      . 
    while(m_threadFrameGenerator == current thread)   . 
   N   m vectFrames. 

      " "    GraphLayout, 
    Visual J++.       
    . 

