© 2000-2003 A-Square, Inc. Cambridge, MA
This code has been purged from the comments that relate to the other 3x exercises.
A functionally equivalent source with the comments retained can be found on Banner3-source.html
>
/*
* @Banner3a 2.0 030105
*
* © A-Square, Inc.
* 175 Richdale Ave, Cambridge MA 02140
*/
import java.awt.*;
import java.applet.Applet;
import java.util.Date;
import rartbase.*;
/**
* A simple Rart universe
* @version 2.0 000928
*
* @author Jan Aminoff
*/
final public class Banner3a extends Universe {
/*
* This source file is provided in sections corresponding to sections
* with the the same name and order of the Universe.java source file.
*/
// Section 1 Identifying the universe
// -------------------------------------------------------------------------
public String getName(){return "Banner3a, a Rart Universe";}
public String getDescription(){ return descr; }
public String descr=
"This universe is used to demonstrate the basic Rart framework \n"+
"in the Introduction to Java Tutorial. It should be compared \n"+
"to the Banner2a applet of the same tutorial. \n" +
" "; // NEVER FORGET THE SEMICOLON!
public String getRartist(){ return "Jan Aminoff 2000";}
// -------------------------------------------------------------------------
// Section 2 What the universe does
// -------------------------------------------------------------------------
// Variables
private int maxv = 8; // Max speed of logo
private int size = 35; // Size of logo
private ASquareLogo logo;
// init(), implementation of abstract method in Universe.
public void init(){
setParams(); //See Section 3
// We collect all reactions to changes in a reset method
reset();
}
private void reset(){
// Note: The two variables xm and ym are available in the parent class
// Universe. They give the size of the available window at all times.
logo = new ASquareLogo(xm, ym, size);
logo.setMaxSpeed(maxv);
} // end of reset
// cycle(g), implementation of abstract method in Universe.
public void cycle(Graphics g){
// Compare with the update method of Banner2a!
// We reset the whole rectangle (0,0, maxx, maxy)
g.setColor(Color.lightGray);
g.fillRect(0, 0, xm, ym); // Paint the screen light gray
logo.drawLogo(g); // Draw the logo
logo.moveLogo(); // Move the logo
String s1 = "Welcome to Introductory Java";
printString(g, s1, 50, 45, 20);
s1 = "Jan Aminoff, Instructor";
printString(g, s1, 120, 80 ,14);
int nn=number.getCur();
s1 = "Also inventor of Rart, random Art for the Internet.";
printString(g, s1,xm-250,ym-5,10);
s1 = "Java Environment: "+
System.getProperty("java.vendor")+"..."+
System.getProperty("java.version");
printString(g, s1, 5, 15 ,12);
} // end of cycle(g)
// manageChange(uP), implementation of abstract method in Universe
public void manageChange(uParameter uP){
/*
* The Banner3a universe has three parameters, with
* index VIEWSIZE, CYCLETIME, and NUMBER respectively
* Section 3 gives the definitions. Here we have to program what to
* do if any of these parameters is modified.
*/
int type = uP.getIndex();
if (type == VIEWSIZE){ // If the size of the screen has changed.
reset(); // Just start all over
}else if (type == CYCLETIME){ // If the cycletime is modified
cycletime = uP; // Make sure cycletime has right value
}else if (type == NUMBER){
number = uP; // number has right value
reset(); // Just start all over.
}
} // end of manageChange(uP)
// getBackground(), overriding method in Universe
public Color getBackground(){return background;}
private Color background = Color.lightGray;
// -------------------------------------------------------------------------
// Section 3 uParameters as used in the universe
// -------------------------------------------------------------------------
// There are two uParameters defined here: cycletime defined almost always,
// and number which is specific to this universe.
private uParameter cycletime;
private uParameter number;
// The setParams() method is called only once, in init(), it is defined here
// in Section 3, so all parameter related stuff is together
private void setParams(){
// First cycletime
// Since "Cycle Time" is a compulsory parameter, the description is
// provided in Universe as CycleTimeDescr.
cycletime = new uParameter
(CYCLETIME,"Cycle Time", 10,50,100, CycleTimeDescr);
// we now have to add the parameter to the array of uParameters
// associated with this universe
adduParameter(cycletime);
// Second number
String ndescr = "In EX2b, EX2c, and EX2d Double click \n"+
"to see this parameter change!";
number= new uParameter
(NUMBER, "Number of objects",0,5,10, ndescr);
adduParameter(number);
} // end of setParams()
// -------------------------------------------------------------------------
// Section 4 Utility Methods
// -------------------------------------------------------------------------
// All provided in Universe, include int RND(int x), printString, etc
// Section 5 Useful Variables
// -------------------------------------------------------------------------
// Provided in Universe, include xm, ym, for width and height of window and
// nc for number of frames.
// Section 6 Security related methods
// Provided in Universe, except for the following constructor.
public Banner3a()throws InstantiationException
{
// Empty statement. This will activate the constructor of Universe
// which only allows the activation of one universe at a time in
// order to preclude bogging down the system by mistake or intent.
}
} //end of definition of Banner3a
>