/*
File: Jabberwocky.java
Author: Kenneth L Moore
Purpose: Class (template) for Jabberwocky Monster. Can be instantiated in
an Applet only.
*/
import java.awt.*;
import java.applet.*;
public class Jabberwocky {
// internal display properties
private Font myFont = new Font("Arial", Font.BOLD, 24);
private boolean displayFlag = false, feedFlag=false;// display
feed or info
// Attributes of Jabberwocky: note these variable can not be
accessed
// directly by the programmer instantating (creating the object)
// Jabberwocky.
private boolean hungry = false;
private String color;
private String sex;
// methods to access instance variables.
public void setSex(String ss){
sex = ss;
};
public void setColor(String cs){
color = cs;
};
public boolean getHungry(){
return hungry;
};
public void setHungry(boolean hflag){
hungry = hflag;
};
public void setDisplayFlag(boolean dflag){
// if set, paint
displays status of Jabberwocky
displayFlag = dflag;
};
public void setFeedFlag(boolean fflag){
// if set, paint
displays eating behavior
feedFlag = fflag;
};
/*
The following method can only be called by paint to function
properly. It needs the
current applet graphics variable to
draw to.
*/
public void displayAttr (Graphics g) {
g.setFont(myFont);
if(displayFlag){
// show attributes
g.drawString(" You have a " + color + " " + sex +".",10,70);
// display inverse of hungry to coincide with toggle logic
g.drawString(" It
is " + !hungry + " that your",10,95);
g.drawString("
JABBERWOCKY is hungry!",10,120);
}
else if(feedFlag){
// show feeding
behavior
if(hungry){
g.drawString(" Mmmmm... A
peasant!",10,70);
}
else if(!hungry){
g.drawString(" Not
hungry... Will be next time!",10,70);
}
}
};
}