a28c2.java compiled by a28c2.html into a28c2.class.
a28c2txt.html = this document.

/* CIS 790                                    PROF. AUCIELLO
w
   (a28c2.java)
    (drag variable name from right to left ..)

USED A NULL IMAGE (IMG0.GIF) FOLLOWING IMG4.GIF TO ERASE TRACKS!

SPEED UP PERFORMANCE FOR WEB!

Lady Bug on the Move, the first Java Motion-Graphic Applet!

GOALS:  motion-graphics.
        contains delay loop to facilitate viewing.
        contains debugging statements.
       
 Topics:   
        .      Access Specifiers: 
        	      Public    = accessible to all classes =
               	      not restricted.
                      Protected = accessible by any class that
                      that extends the current class.
                      Private   = accessible by only the methods
                      in the same class.
        .      Printing a literal string.
	        (using System.out.println)
        .      'public'
        .      Inputting a String.
        .      x (hor) and y (ver) coord for drawString
        .      Fonts
        .      Life cycle of an Applet:
               init(), start(), stop(), destroy()  (not yet)
        .      Defining and initializing variables (int x = 50)
        .      incrementing   (x =+ 50)
        .      3 colors, 3 loops.
        .      changing windows to view red, green, blue counters.
        .      FONTS, COLORS, LOCATION as an Applet
        .      changing windows as debugging tool
               (using System.out.println).
        .      'flicker'  (image retention on crt)
        .      repeat after me:  because of the flicker-factor,
               the blank cycle has to last 150 loops of x (.1 sec)
               both the display cycle and the blank cycle need to
               last about .1 second for human factors.
        .      for and while loops.
        .      blanking out one char at-a-time.
        .      in graphics, overwriting is pixel-by-pixel!
        .      pre- vs  post-incrementing  (watch this!)
        .      break = exit out of loop.
        .      use yellow to erase yellow, dummy.
                 PRINTING MARK IN YELLOW WIPES OUT MARK IN RED,
                 EVERY PIXEL THEREIN!
        .       requires understanding that drawString is a
                pixel-printer!

questions:  (scratch pad)
        how to erase information from screen?   -- fixed.
        does an applet continue to run?   Yes.
        Mark is on screen, running.  Put in counter.    -- done.
        making init() time  -- not discussed.
        passing strings from one method to another?
        passing on init() time ...     (not covered)
        how to erase a byte?    -- got it.
        put time delay between drawStrings.  -- done.
        both M and X are printing.
        counted to 1000 almost immediately.   (about 1 second).
        time delay = 10000.  slows for 10 seconds
        5000 = 6 seconds.
        1000 = about 1 second.
        check out repaint() -- got it!
        no display.  why?    (went back to 'backup')
        comment out all repaint()  -- testing 
        modifying { }   -- talk about style.
        putting red color back in.
        blank out a name then reposition it.
        why does middle string print every 5 seconds?        
        trying to move name ...
        names do get 'erased'
        now try dragging name from  220 to 1 in 10 steps.
        move more to right ..
        lots of 'bleed-over '  think 40 frames / second.
        does Java read your comments?  YES.  see Unicode.
        not erasing enough chars -- check font : pixel size, etc.
                  (about 1 char = 5 horiz spaces!)
        only first 5 chars blanking out!
        printing @ hor, must blank @ hor!  -- of course!
        why does it end prematurely?       -- fixed loop.
        why does it only blank 4 letters?
        put an M at 1,15, try to blank it out! -- successful!
        put a Mark at 1,15, try to blank it out! -- works!
        what erases Mark? -- repaint() or g.drawstring?
        repaint() does not work except for an entire line?  why?
                 REPAINT() is used to do paint method again.
        why the inconsistency of timing? -- fixed with test before printing.
        concentrate on erasing previous Mark -- got it!

        comment on relationship between critical thinking (testing
        hypothesises) and imaginative thinking (going beyond
        the lines!) how they must team up (called "hacking")
        to make an effective programmer!

        clues:  always define something before using it!
                good practice to define / initialize all variables
                early in program.
                'break' must precede the loop it 'breaks out of'



THE 1ST MOTION-GRAPHIC APPLET BEGINS!
---------------------------------------------------------- */
// genesisz.java   by  J. Auciello, 10/98
//  a28c2.java   May.1999

import java.applet.Applet;
import java.awt.Graphics;      // req. for app & prog
import java.awt.image.*;       // req for images.
import java.awt.*;
import corejava.*;             // req. for applet

public class a28c2 extends java.applet.Applet // req for app

{ public TextField inputField;

  public void init()
      { inputField = new TextField(15);
        add (inputField);
        inputField.setText("Enter Name: "); 
      }

  public void paint(Graphics g)   // req for app
      { int red = 17; int gre = 17; int blu = 17; int x = 1; int dumvar = x;
        int hor = 1;

        Image gifname  = getImage(getDocumentBase(),"img4.gif");      
        Image gifname1 = getImage(getDocumentBase(),"img0.gif"); 
                         // image with no content.
            
        String yourname;
        String s  =  inputField.getText();
        yourname  =  "Lady Bug on the move -- 1st Motion Graphics! by " + s;

        Font fs = new Font("Sans Serif", Font.BOLD, 12);   // define Font
        Font fm = new Font("Monospaced", Font.BOLD, 14);   // define Font
        g.setFont(fs);   // setFont, part of the graphics 'library',
                         // now 'linked' with the program.
                        
        setBackground(Color.yellow);
        g.setColor(Color.red);
  
        g.setFont(fm);
        hor = 420;

        outerloop:
          while ( dumvar <= 2 )
                { g.setColor(Color.red);
                  hor = hor - 30;
                  if (hor < 60)
                  { hor=420; break outerloop; }   // syntax of "if .."
                  g.drawString(yourname, hor, 75);
                  g.drawImage(gifname, hor, 140, this);
                  x = 1;
                  while ( x < 4 )  //  delay to reduce flicker.
                                     // syntax of "while"
                  {  System.out.println("x = " + x);
                      g.drawString(" " + x, 1, 1);
                     x ++;
                  }
                    // System.out.println("end = " + "\u0007");   // rings bell.
                    // System.out.println("hor =" +hor);  // debugging tool.
                    g.setColor(Color.yellow);
                    g.drawString(yourname,hor, 75);
                    g.drawImage(gifname1, hor, 140, this);
                      // this is how to erase trail.  go figure!
                    repaint();   // invokes 'paint' method yet another time.
                  }
  }  // end protected access specifier.
}  // end class.

// ----------------------------------
// end of source program.
// a28c2 1 x

/* Students should comment every line.  Save original working
   copy as  ver1 ... then make changes, saving as ver2, etc.
   leaving yourself the opportunity to go back to the last working
   copy.

   You should get out of this how to erase  graphics
   both yourname and image were erased using the same technique!

   Put your name in front of the bug and have her chase you
   right to left.

   Show me what you know.

   Animation needs to take into account -- frames per second.
   To slow this down, check the loop (166-170) that drew a line
   at 1,1.   Think about the impact of this.  Remove statement
   and try.

   

   
*/