/**************************************************************************** #* Copyright 2000 University Of Michigan - Dearborn. All Rights Reserved. #* CIS 525 - Dr. Maxim - Web Programming #* November 13, 2000 #****************************************************************************** #* Name: smileyprogram.java #* Description: This Java applet displays five different faces or moods of a #* face. There are three methods in the program. Method init, paint and #* Action. #* There are two attributes, complete and completepanel. #****************************************************************************** #* The following are the 3 methods in proram smiley * #* public void init() * #* public void paint (Graphics g) * #* public boolean action(Event e, Object arg) * #****************************************************************************** #* * #* * #*------------------------------------------------------------------------- * #* Revision History * #*========================================================================== * #* Date SE CSR Description * #* ---------- --- -------- ----------------------------- * #* 11/01/00 Mark Chaaban C0001 Initial release. Based on * #* Page CIS 525 webpage . * #* * #* 11/07/00 Mark Chaaban C0002 Updated additional 2nd 3rd faces to * #* applet * #* * #* 11/11/00 Mark Chaaban C0003 Updated 4th and 5th face to applet * #* * #* 11/12/00 Mark Chaaban C0004 Updated all documentation and * #* created online javadoc * #******************************************************************************/ import java.awt.*; import java.applet.Applet; /** * This class extends applet which displays smiley face in different * moods and formats The different formats can be chosen from the drop * list box provided on the top right of the applet. * */ public class smileyprogram extends Applet { /** This attribute holds the choice selected by the user on the drop down list box of the applet. */ Choice complete; // declare the Choice menu /** This attribute holds the drop down list box on the right hand side of the applet */ Panel completePanel; // declare the panel to hold the menu /** * This method is invoked by all applets, this is an entry point * of the smiley program. The panel is initialized and a label is * added here. Also the choices are initialized and the the menu items * for the drop down are added. They are the following, (Smiley, Fruity, * Surprised, Sad, and Weird.) The panel is added to the applet and its * Validated. */ public void init() { setSize( 450,450 ); completePanel = new Panel(); // initialize the panel and add a label completePanel.add(new Label("What is your mood today?:")); complete = new Choice(); complete.addItem("Smiley"); // initialize the Choice and add the menu items to it. complete.addItem("Fruity"); complete.addItem("Suprised"); complete.addItem("Sad"); complete.addItem("Weird"); completePanel.add(complete); // add the Choice to the panel. add(completePanel); // add the panel to the applet. validate(); // validate it } /** * This method paints the actual smiley faces on the applet * All the variables needed to hold the coordinates of the * Components of the face are given their values. */ public void paint (Graphics g) { // declare many variables needed to hold the coordinates of the // components of the faces g.setColor(Color.white); g.fillRect(0,0,450,450); switch(complete.getSelectedIndex()) { #****************************************************************************** #* Below are the many variables needed for the drawing and filling of the * #* head, eyes, nose, mouth, ears and also the filling of the arcs of eyes * #* and mouth. * #****************************************************************************** case 0: // drawing head g.drawOval(30,50,300,300); g.setColor(Color.yellow); g.fillOval(31,51,298,298); // drawing & filling left eye g.setColor(Color.black); g.drawOval(110,110,20,35); g.setColor(Color.white); g.fillOval(111,111,18,33); // drawing & filling right eye g.setColor(Color.black); g.drawOval(230,110,20,35); g.setColor(Color.white); g.fillOval(231,111,18,33); // filling arcs in eyes g.setColor(Color.black); g.drawArc(110,130,20,20,20,140); g.fillArc(111,129,18,18,20,360); g.drawArc(230,130,20,20,20,140); g.fillArc(231,129,18,18,20,360); // drawing the mouth g.setColor(Color.black); g.drawArc(105,210,150,100,0,-180); g.setColor(Color.yellow); g.fillArc(105,240,150,30,0,-180); // drawing nose g.setColor(Color.black); g.drawOval(160,140,40,60); // drawing ears g.drawOval(5,160,25,80); g.drawOval(330,160,25,80); g.setColor(Color.yellow); g.fillOval(6,161,24,79); g.fillOval(331,161,24,79); g.setColor(Color.black); g.drawOval(10,180,13,40); g.drawOval(335,180,13,40); break; #****************************************************************************** #* Below are the many variables needed for the drawing and filling of the * #* head, eyes, nose, mouth, ears and also the filling of the arcs of eyes * #* and mouth. * #****************************************************************************** case 1: g.drawOval(30,50,300,300); g.setColor(Color.red); g.fillOval(31,51,298,298); //left eye g.drawOval(110,110,20,35); //draw oval //fill the inside of the oval g.setColor(Color.black); g.fillOval(111,111,18,33); //right eye g.setColor(Color.green); g.drawOval(230,110,20,35); g.setColor(Color.green); g.fillOval(231,111,18,33); // mouth g.setColor(Color.black); g.drawArc(105,210,150,100,0,-180); g.setColor(Color.blue); g.fillArc(105,210,150,100,0,-180); g.setColor(Color.black); g.drawArc(105,240,150,30,0,-180); g.setColor(Color.yellow); g.fillArc(105,240,150,30,0,-180); break; #****************************************************************************** #* Below are the many variables needed for the drawing and filling of the * #* head, eyes, nose, mouth, ears and also the filling of the arcs of eyes * #* and mouth. * #****************************************************************************** case 2: // drawing head first g.drawOval(30,50,300,300); g.setColor(Color.yellow); g.fillOval(31,51,298,298); // drawing & filling left eye next g.setColor(Color.black); g.drawOval(110,110,20,35); g.setColor(Color.white); g.fillOval(111,111,18,33); // drawing & filling right eye next g.setColor(Color.black); g.drawOval(230,110,20,35); g.setColor(Color.white); g.fillOval(231,111,18,33); // filling arcs in eyes g.setColor(Color.black); g.drawArc(110,130,20,20,20,140); g.fillArc(111,129,18,18,20,360); g.drawArc(230,130,20,20,20,140); g.fillArc(231,129,18,18,20,360); //drawing and filling arcs for mouth g.setColor(Color.black); g.drawArc(105,210,150,100,0,-180); g.setColor(Color.red); g.fillArc(105,210,150,100,0,-180); g.setColor(Color.black); g.drawArc(105,240,150,30,0,-180); g.setColor(Color.yellow); g.fillArc(105,240,150,30,0,-180); // drawing nose & ring g.setColor(Color.black); g.drawOval(160,140,40,60); //g.drawOval(190,190,10,10); //drawing teeth g.setColor(Color.black); g.drawRect(165,270,10,10); g.fillRect(166,271,9,9); g.drawRect(180,270,10,10); g.fillRect(181,271,9,9); break; #****************************************************************************** #* Below are the many variables needed for the drawing and filling of the * #* head, eyes, nose, mouth, ears and also the filling of the arcs of eyes * #* and mouth. * #****************************************************************************** case 3: // drawing head first g.drawOval(30,50,300,300); g.setColor(Color.yellow); g.fillOval(31,51,298,298); // draw eyes g.setColor(Color.black); g.drawArc(140,140,55,55,0,180 ); g.drawArc(240,140,55,55,0,180); g.setColor(Color.red); g.fillArc(140,155,55,25,0,360); g.fillArc(240,155,55,25,0,360); // mouth g.setColor(Color.black); g.drawArc(105,210,150,100,0, 200); // draw hair g.setColor(Color.blue); g.drawLine(170,80,140,40); g.drawLine(235,75,260,40); g.setColor(Color.blue); g.drawLine(200,75,195,40); break; #****************************************************************************** #* Below are the many variables needed for the drawing and filling of the * #* head, eyes, nose, mouth, ears and also the filling of the arcs of eyes * #* and mouth. * #****************************************************************************** case 4: //draw head g.setColor(Color.yellow); g.fillOval(50,50,400,400); //eyes g.setColor(Color.white); g.fillOval(160,150,45,70); g.fillOval(290,150,45,70); g.setColor(Color.black); g.fillOval(163,175,38,45); g.fillOval(293,175,38,45); //mouth g.setColor(Color.green); g.fillArc(137,210,220,180,15,-200); break; default: } } /** * This method takes event from the list box on applet * and creates the appropriate smiley face. * this applet overrides the action method of applet to * provide implementation of the list box or drop down choice. * @returns boolean - the return type is a boolean */ // action. the function that does the work public boolean action(Event e, Object arg) { if (e.target instanceof Choice) //this applet overrides the action method of applet to //provide implementation of the list box or drop down choice. { repaint(); return true; } return false; } }