/* CIS 790       Hello! ... World from User         Prof. Auciello 

Read Chapter 8.  TYJI21D by Laura Lemay ...

Topics:   DO ... WHILE LOOP	FONT
	  SCREEN POSITIONS      COLORS
          RUNNING IN HTML
*/

// TO LEARN THIS ASSIGNMENT WELL, 
// (1) CUT OUT THE SOURCE CODE (BETWEEN THE ===== LINES)
//     AND COMPILE IT, AND RUN WITH NETSCAPE OR EXPLORER.
// (2) ONCE IT IS RUNNING, AND YOU HAVE MASTERED THOSE
//     SKILLS, DROP BACK TO KEYING IN EACH LINE OF CODE,
//     AND COMMENTING EACH LINE OF CODE.  (SEE EXAMPLES)
//     USE (?) WHEN YOU DON'T KNOW.
// (3) COMPILE USING 'JAVAC'  (example below)
//     SUFFER THE PANGS OF THE COMPILE PROCESS.
//     EACH COMPILE ERROR THAT IS CORRECTED REINFORCES
//     LEARNING.
// (4) WHEN YOU HAVE A CLEAN COMPILE, CUT OUT THE 4 LINE
//     HTML PROGRAM (hwloop.html) BELOW.
//     BE SURE THAT THE EXTERNAL FILE NAME OF YOUR PROGRAM
//     (THE 'PROGRAM' NAME) IS THE SAME AS THE INTERNAL
//     'CLASS' NAME.  (NOTE THAT THE 'CLASS' NAME IS
//     PUT INTO THE HTML USING THE 'APPLET' TAGS.)
// (5) THEN TEST IT WITH A BROWSER.
// (6) SUPPLY PICTURE AS A .GIF (SCANNER OR DIG. CAMERA)
//     INSERT YOUR MUG SHOT.
// (7) STAND BY FOR INSERTING A VIDEO STREAM OF YOURSELF.
// (8) PLAN TO GET A WEB SITE -- TRIPOD OR WHATEVER -- SHORTLY.
//     FOR YOUR HOME PAGE, AND SOME OF THESE DUMB ASSIGNMENTS.       

// hwloop.jav follows:
// SOURCE CODE BEGINS:
// ============================================================
// step 1.  define all library links.

import java.applet.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.Color;           // color
import java.awt.event.*;
import java.awt.Font;            // font
import java.awt.Graphics;        // graphics library
import java.awt.image.*;         // req for images.
import java.lang.Math;
import java.util.Date;
import java.util.Random;
import java.util.*;

// step 2.  define a class named 'hwloop' that extends and
//          inherits from java.applet.Applet class.
public class hwloop extends java.applet.Applet    // declares class.
{ 
  //step 3. define all global variables.
  TextField textField1;          // define textfield1
  Font ftr24 = new Font("TimesRoman", Font.ITALIC, 24);
  Font fss36 = new Font("Sans Serif", Font.BOLD, 36);   // define Font
  String name;
 
  // step 4.  create an init() method
  public void init()
   {   
       // Step 4a. Prompt for name.
       Label namelabel1 = new Label(" Enter Your Name ",Label.RIGHT);
       add(namelabel1);  
       textField1 = new TextField(15);
       add(textField1);                    // add textfield to structure     
       
       if (name == null)
            name = "Harvey";
   } // end init method

  public void paint(Graphics g)
   {  // Step 5.  paint() method (displays output)
      // step 5a.  get an an image. Insert yours if possible.
      Image gifname270 = getImage(getDocumentBase(),"MONICA.GIF");  

      g.setFont(fss36);   // setFont, part of the graphics 'library',
                          // now 'linked' with the program.
      setBackground(Color.yellow);
      g.setColor(Color.blue);
      g.drawImage(gifname270, 400, 65, this);
      g.drawString ("Hello World", 5, 145);
      g.drawString ("from " + name + "! ",5,180);
      g.setFont(ftr24);
      g.drawString ("In blue on yellow at 36 points!", 5, 245);
   } // end of paint method

//  Step 6. "listen" when the "enter button" is clicked.
    public boolean action(Event event, Object arg)
      {                  
        name     = textField1.getText();    // get name
        repaint();
        return true;
      }  // end event-listenig method.
} // end of applet.

// SOURCE CODE ENDS
// ============================================================


/*  Steps to Sanity:

   1.  Have clean source code ready-to-compile.  done.
   2.  In a subdirectory containing  java.exe and javac.exe
       compile source using the following:

       javac hwloop.java

                  Done.  Had several syntax errors.
                         "color" is spelled "Color"

  3.  Run Dir hwloop.*    to check for Class output.

      Here's what the screen looks like:
===============================================================

C:\Jdk1.1.2\bin>javac hwloop.java
                                 (no message means no problem)
C:\Jdk1.1.2\bin>dir hwloop.*
                                 (all files beg. w. hwloop)             
  Directory of C:\Jdk1.1.2\bin
 (old DOS)                                   (DOS 95)
HWLOOP~1 JAV         1,209  09-03-99  6:59p hwloop.java
HWLOOP~1 CLA           717  09-03-99  7:04p hwloop.class
         2 file(s)          1,926 bytes
         0 dir(s)      23,085,056 bytes free
===============================================================

Got the source and the object-output (class) file:
(Note the extremely tricky old DOS names on the left
 and the Win 95+ DOS Names on the right.)

Yes.  hwloop is there and ready to be 'embedded')
Let's do it:

Listing of hwloop.html 
============================================================
<html> 
<APPLET CODE="hwloop.class" WIDTH=600 HEIGHT=300>
</APPLET>
</html>
============================================================

  4.  Stare at this till you realize that the output of the
      compiled hwloop.java  source program -- which is 
      hwloop.class -- gets put smack in the midst of this
      html set!

      Run the HTML,  run the Java Applet!

   
  5.  Testing it.  Got text and bkgrnd color.  Got font. Got Param.

  6.  Adding User-Input of Name;  Picture.   Got it.


Font Options:
  //	Font fb= new Font("TimesRoman", Font.BOLD, 24);
  //	Font fp= new Font("TimesRoman", Font.PLAIN, 24);
  //	Font fbi=new Font("TimesRoman", Font.BOLD + Font.ITALIC, 24);


*/