import java.awt.*; public class Smiley extends Canvas implements SmileyEmotions { // smiley's "emotion" property protected int emotion; //------------------------------------------------------------------- // Smiley Constructor //------------------------------------------------------------------- public Smiley() { emotion = SMILEY_HAPPY; setFont(new Font("Courier", Font.BOLD, 34)); } //------------------------------------------------------------------- // set()/get() for 'Emotion' property //------------------------------------------------------------------- public void setEmotion(int value) { emotion = value; } public int getEmotion() { return emotion; } //------------------------------------------------------------------- // Fix the size of our bean. We don't support stretching or shrinking //------------------------------------------------------------------- public Dimension preferredSize() { return new Dimension(70,40); } public Dimension getPreferredSize() { return preferredSize(); } //------------------------------------------------------------------- // paint() refreshes our bean's graphical representation (a smiley!) //------------------------------------------------------------------- public void paint(Graphics g) { drawSmiley(g); } //------------------------------------------------------------------- // drawSmiley() renders our smiley (in classic email orientation) //------------------------------------------------------------------- protected void drawSmiley(Graphics g) { String smileyStr; smileyStr = smileyChars[emotion]; // find which smiley to draw g.drawString(smileyStr, 5,25); // e.g. ":-)" } } // End of Class Smiley