// CIS 790     Java Programming     L.A.T.T.C       PROF. AUCIELLO
//
/*  Assignment: (200 points)





General:
     Explain each line using // (comments)   see examples below.
     Run this use your name, and vary # iterations (careful not
     to have too many -- 500 iterations takes about 30 seconds).
     (depends on baud rate, cpu speed).
     Gain a sense of how colors are formed.
     Learn how to input variables to an Applet.
     While the art is interesting, it serves to set the table
     for the programming concepts involved such as
     color as  having red-green-blue components.
   
Programming:
     Modify program to print  output like  212-123-65
                                           red-gre-blu
     in random locations.                 
     Change "Start" button to "Go" button.
     Add a 2nd input field that also is displayed randomly.
     (Fill the screen with random "X" and "0").
     Add error trapping (try ... catch)
     Show me what you can do.

CQII (Continuous Quality Improvement and Innovation) in programming means 
pushing toward the edge with continual improvement using the highest
quality output and coding techniques.       


    TOPICS
        - Labels, Buttons                 - Event Processing
        - Text Input Fields               - KB Input to an Applet
        - Boolean methods                 - Mondarian (output as art)
        - RGB demonstrated                - canvas size
        - hor, ver coordinates            - init() vs start() time
        - random number generation        - String to Int conversion
        - Int to String conversion        - Trace Statements
        - initializing Prompts

*/

//  Programming / Debugging Log
//  converting integer to String
//  adjusting resize
//  changed to start(), not init().
//  why is 's' not defined?
//  replace 'extract' with 'start'.  done.
//  will add start button to program.
//  testing colors.   off screen or too light.   more adj.  above.
//  adj.  ver, hor.   fixing prompts. done.
//  shrink size of reload   24  done.   20% more width.  ver now = 700.
//  enter name prompt.  311 ... 601     added prompt.
//  added # iterations.

// mondarian

import corejava.*;
import java.applet.*;
import java.awt.*;
import java.awt.Graphics;
import java.awt.Font;
import java.awt.Color;
import java.lang.Math;
import java.util.Date;
import java.util.Random;
import java.util.*;

public class auci15 extends Applet
{ int n;
  TextField textField1,textField2,textField3,inputField1,inputField2,inputField3;
  Button button1, button2;
  String displayStr, s, ns, blankstr;

  public void start()
    { Label namelabel = new Label("Enter Your Name: ",Label.LEFT);
           //  Defines a label named "namelabel" as new that
           //  contains "Your Name", justified left
      add(namelabel);  // added 'namelabel' as a component
      inputField1 = new TextField(15);
      add(inputField1);
      inputField1.setText("Lucinda Auciello");

      Label countlabel  = new Label("Iterations: ",Label.CENTER);
      add(countlabel);
      inputField2 = new TextField(4);
      add(inputField2);

      button1     = new Button("Start");
      add(button1);  
      
      blankstr   = "                         ";
      displayStr = "";
      resize(600, 375);
    } // end start

    public void paint(Graphics g)
    { int rval, gval, bval, x=0, ver=0, hor=0;
      Font f    = new Font("TimesRoman", Font.ITALIC, 24);
      Random r  = new Random();
     
      while (x < n)
         {hor  = Math.abs(r.nextInt()%520+1);
          ver  = Math.abs(r.nextInt()%230+1);
          rval = Math.abs(r.nextInt()%224+1);
          System.out.println("x:n = "+x+" : "+n);
          gval = Math.abs(r.nextInt()%224+1);
          bval = Math.abs(r.nextInt()%224+1);
          g.setFont(f);
          g.setColor(new Color(rval,gval,bval)); // get random color.
          g.drawString(s,hor,ver+70);
          // g.drawString(""+rval+"-"+gval+"-"+bval,150,150);
          String xs = ""+x;    // neat integer to string conv trick.
          // g.drawString(xs,150,150);
          x++;
         }  // end while group
    }  // end paint class
        
    public boolean action(Event evt, Object arg)
    { if (arg == "Start")
         { s    = inputField1.getText();
           ns   = inputField2.getText();
           n    = Integer.parseInt(ns);
           repaint();
           return true;
         }  // end "then group.
      else 
          return false;
    }  // end action
}  // end class 

// Note structure of program --
// defining variables
// start() method
// paint()
// event listener.

/*  Questions:
    When do you have to use Label?
    Change size of input text field?
    What does displayStr = "" do?
    Are the parameters of resize(600,375)  ver,hor   or  hor,ver ?
    Change 'start()' to 'init()'     -- any difference?
    How do you 'read' or 'get' text from an input field?
    How do you convert a string to an integer?
    Convert integer to string?
    How would you test to see if some RGB combinations are
    too light to be read on a white background?
    (How can you find out how  various rgb combinations look like?)
    How do you change a font?
    How are colors set?
    Is  "ffffff"  or "000000" when RGB is the lightest?
    How do you generate a random number between 0 and 224?
    What does 'Random r = new (Random)' do?
    What causes the 'while (x < n)' loop to exit?
    Does this program display any text in any colors in any locations?
    Can you think of a way to improve it?
    Get into this program.  Take it apart.  add to it.  Save it
    under different names (version numbers).   Test and Improve it.

*/