Name of applet class file:       a28c3.class
Name of Java program:            a28c3.java
Name of this lesson:             a28c3txt.html
Name of the html that compiled:  a28c3.html

a28c3.html compiled a28c3.java into a28c3.class.

/* CIS 790                                PROF. AUCIELLO

   (a28c3.java)
    (drag variable name from right to left ..)
    (4 sequential gifs of ladybug ...  should do flips now)

      using 26000 loops (internal) between images!

Lady Bug on a Roll - 1st 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)
        .      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)
        .      FONTS, COLORS, LOCATION as an Applet
        .      debugging: changing windows to view red, green, blue counters.
               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)  (log of activities)
        how to erase information from screen?   -- fixed.
        does an applet continue to run?   Yes.
        Mark is on screen, running.  Put in counter.    -- done.
        passing strings from one method to another?
        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!
        blank out a name then reposition it.
        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!)
        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
        hypotheses) 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 a28c3 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 gifname270 = getImage(getDocumentBase(),"slb270.gif");     
      Image gifname180 = getImage(getDocumentBase(),"slb180.gif");  
      Image gifname090 = getImage(getDocumentBase(),"slb090.gif"); 
      Image gifname000 = getImage(getDocumentBase(),"slb000.gif"); 
      String s  =  inputField.getText();
      
      String yourname;
      yourname  =  "Lady Bug on a roll! - 1st Motion Graphics by " + s;

      Font fs = new Font("Sans Serif", Font.BOLD, 18);   // define Font
      Font fm = new Font("Monospaced", Font.BOLD, 16);   // 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(fs);
      hor = 670;

      outerloop:
        while ( dumvar <= 2 )
              { g.setColor(Color.red);
                hor = hor - 37;
                if (hor < 37)
                   { hor=670; break outerloop; }   // syntax of "if .."
                     // g.drawString(yourname, hor, 95);
                     int xc = 0;

                     for (int lbc = 1; lbc < 6; lbc ++)
                       { g.setColor(Color.yellow);
                         g.drawString(yourname, hor, 95);
                         hor = hor - 37;
                         g.setColor(Color.red);
                         for (xc=0; xc<260000; xc++);
                         {  g.drawImage(gifname270, hor, 265, this);
                            g.drawString(yourname, hor, 95);         }
                        

                         g.setColor(Color.yellow);
                         g.drawString(yourname, hor, 95);
                         hor = hor - 37;
                         g.setColor(Color.red);
                         for     (xc=0; xc<260000; xc++);
                           { g.drawImage(gifname180, hor, 265, this);
                             g.drawString(yourname, hor, 95);         }


                         g.setColor(Color.yellow);
                         g.drawString(yourname, hor, 95);
                         hor = hor - 37;
                         g.setColor(Color.red);
                         for     (xc=0; xc<260000; xc++);
                           { g.drawImage(gifname090, hor, 265, this);
                             g.drawString(yourname, hor, 95);         }


                         g.setColor(Color.yellow);
                         g.drawString(yourname, hor, 95);
                         hor = hor - 37;
                         g.setColor(Color.red);
                         for     (xc=0; xc<260000; xc++);
                           { g.drawImage(gifname000, hor, 265, this); 
                             g.drawString(yourname, hor, 95);        }

                       }  // outer for
                                  
                  x = 1;
                  while ( x<150 )  // 1 sec delay to reduce flicker.
                                   // syntax of "while"
                  { System.out.println("x = " + x); x += 1; }  // end
                    // System.out.println("end = " + "\u0007");   // rings bell.
                    System.out.println("hor =" +hor);  // debugging tool.
                    g.setColor(Color.yellow);
                    g.drawString(yourname,hor, 95);
                    repaint();   // invokes 'paint' method yet another time.

              }  // end of outer while     
    }  // end protected access specifier.
}  // end class.

// ----------------------------------
// end of source program.
// a28c3

Note from Prof. A:  My associates and I are thinking now that the 
difficulty in learning Java is related to its paradigm-shifting,
rapidly-improving, extreme range of power.  A student has to learn
basic programming functions -- for and while loops, if .. then .. else,
break, then learn and apply the concepts of class, inheritance, then
then advanced features working with color, animation, etc.  

Java is new and growing up rapidly, being pulled to maturity by
a rapidly evolving internet, and smart devices.

The approach that we are taking is that by "learning and doing",
checking, revising, retesting, and building on successful blocks,
the student will gain both complete comprehension and programming
skills.  This we are calling the "Accelerated Learning Glass Box 
Approach" (based partly on Glass Box programs by Howard Pellee).

Thus it is critical and imperative that a student has the source code
in front of him or her while they run the program, and they must interact
with it, "tweak and peak", and test every part of it for understanding.

Comment it heavily.  Modify some code.  Improve it.  Then go on to the
next one.  IT IS ONLY BY MODIFYING, TESTING, APPLYING THEORY, TESTING
THEORY, AND DOING do we believe that we can make the student proficient
in Java Programming.  

Each lesson is conditioning calisthenics for the Java Tri-Athelon.
(something like that).

You should put in hours on each program, and build a library of
successfully modified, compiled, executed programs with an understanding 
of what each one does.

For this program, you should have got:

	problems with animation (flicker and timing).
        creating aninmation by moving and erasing images.
        prerequisite skills with a graphics editor to
        crop images, etc.
        skills using an Internet Browser.
        using "System.out.println" to debug.

Put forth the effort.  Java and its family will inherit WEB programming!

Joseph Auciello
May 12, 1999