How to...

d-k-k edited this page Jun 29, 2015 · 11 revisions

A file is located in the examples folder for each entry.

How to...

Hello World
Create Basic Shapes
Create A Polygon
Basic Animation - Moving Text

Hello World

import java.awt.Color;

/**
* For all example files, move them to the same folder that the EZ.java file is located and compile.
*/

public class HelloWorld {

	public static void main(String[] args) {

	  //The following will create a window with the specified width and height;
	  int width = 100;
	  int height = 100;
	  EZ.initialize(width, height);
	  
	  /* The following will place the text "Hello World".
	   * It will be centered at position 50,50 (half the window, so also in the middle of the window).
	   * The color to render the text in is black.
	   * It is using the Java's class definition for color, which is why the import statement at the top is necessary.
	   */
	  int xCenter = 50;
	  int yCenter = 50;
	  String msg = "Hello World";
	  Color c = Color.black;
	  EZ.addText(xCenter, yCenter, msg, c);

	} //end main
} //end class

Create Basic Shapes

import java.awt.Color;

/**
 * EZ comes with two basic shapes, circles and rectangles.
 */

public class CreateBasicShapes {

  public static void main(String[] args) {
    EZ.initialize(500, 500);
    
    /* Circles and rectangles require 6 attributes to be created, they are:
     * x and y center location.
     * width and height.
     * color.
     * and fillStatus, whether or not it should be filled or just an outline.
     * 
     */
    int xCenter = 125;
    int yCenter = 125;
    int width = 250;
    int height = 250;
    Color color = Color.blue;
    boolean fillStatus = true;
    //This will create a blue circle a blue circle
    EZ.addCircle(xCenter, yCenter, width, height, color, fillStatus);
    
    xCenter += 250;
    /* With a window of 500x500. The initial xCenter of 125 will place the first circle in the upper left corner.
     * The previous line will add 250 to the xCenter variable.
     * This will not affect the first circle.
     * Instead it will affect where the following circle is made.
     */
    EZ.addCircle(xCenter, yCenter, width, height, color, fillStatus);
    
    width = 150;
    height = 150;
    color = Color.red;
    //This next circle will be on top the right one, but a red and smaller.
    EZ.addCircle(xCenter, yCenter, width, height, color, fillStatus);
    
    width = 50;
    height = 50;
    color = Color.green;
    //A third for the stack, smaller and green.
    EZ.addCircle(xCenter, yCenter, width, height, color, fillStatus);
    
    
    //start with making a backdrop
    width = 500;
    height = 250;
    xCenter = 250;
    yCenter = 375;
    color = Color.black;
    EZ.addRectangle(xCenter, yCenter, width, height, color, fillStatus);
    
    //Now for some rectangles.
    width = 100;
    height = 100;
    xCenter = 100;
    yCenter = 375;
    color = Color.green;
    EZ.addRectangle(xCenter, yCenter, width, height, color, fillStatus);
    
    int xmod = 50;
    int ymod = 50;
    for(int i = 1; i <= 6; i++) {
      if(i % 2 == 0) { ymod *= -1; }
      xCenter += xmod;
      yCenter += ymod;
      
      if( i % 3 == 0) { color = Color.orange; }
      if( i % 3 == 1) { color = Color.cyan; }
      if( i % 3 == 2) { color = Color.magenta; }

      EZ.addRectangle(xCenter, yCenter, width, height, color, fillStatus);
    } //end for i <= 6
    
  } //end main
} //end class

Create A Polygon

Basic Animation - Moving Text

import java.awt.Color;

/**
 * Creating a basic animation with moving text.
 * 
 * This will require the user to keep a reference to the object and use an updater loop.
 *
 */
public class BasicAnimationMovingText {
  
  public static void main(String[] args) {
    EZ.initialize(300, 100);
    
    /* Creates text in the middle of the window displaying "I'm moving..."
     * But also puts the reference into variable text.
     * This allows later manipulation of the visual element.
     */
    EZText text = EZ.addText(150, 50, "I'm moving...", Color.black);
    
    /* The while true loop is an always activating loop.
     * At this point, the program will continue to perform the contents of the loop.
     */
    while(true) {
      /* This next call is necessary for animation.
       * It does many things in the background, but the main think to know is that this call is what will
       * update all visual changes through manipulation.
       */
      EZ.refreshScreen();
      
      /* The translateBy() method takes two parameters, the first value is for x, the second is for y.
       * The object will alter its current position by the specified amount in pixels.
       * In this case, it moves 1px to the left and has no change in the y axis.
       */
      text.translateBy(-1, 0);
      
      /* There would be nothing left to see if the text goes off the screen.
       * First a check is made to see if it is completely off screen,
       * if so, then move to the right side of the screen.
       */
      if( text.getXCenter() + text.getWidth() < 0 ) {
        text.translateBy(EZ.getWindowWidth() + text.getWidth() * 2, 0);
      }
      
    } //end updater loop
    
  } //end main
} //end class
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.