Results 1 to 4 of 4

Thread: Absolutely lost

  1. #1
    Heyman is offline Member
    Join Date
    Feb 2011
    Posts
    1
    Rep Power
    0

    Default Absolutely lost

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    
    public class Smiley extends JApplet
    {
    
    	//These are all global variables - you can access them from anywhere in this class
    	public static final int FACE_DIAMETER = 200;
    	public static final int X_FACE = 100;
    	public static final int Y_FACE = 50;
    	   
    	public static final int EYE_WIDTH = 10;
    	public static final int EYE_HEIGHT = 20;
    	public static final int X_RIGHT_EYE = 155;
    	public static final int Y_RIGHT_EYE = 95;
    	public static final int X_LEFT_EYE = 230;
    	public static final int Y_LEFT_EYE = Y_RIGHT_EYE;
    	   
    	public static final int Y_NOSE = 135;
    	   
    	public static final int MOUTH_WIDTH = 100;
    	public static final int MOUTH_HEIGHT = 50;
    	public static final int X_MOUTH = 150;
    	public static final int Y_MOUTH = 175;
    	public static final int MOUTH_DEGREES_SHOWN = 180;
       	
    	public int noseDiameter = 10;
    	public int xNose = 195;
    	public int mouthStartAngle = 180;
    	public String eyeColor = "";
    
    	//the init function is similar to main function in Java Classes
    	public void init(){
    		setSize(400,400);
    		String inputString = JOptionPane.showInputDialog("Which would you like to change?\nMOUTH, NOSE, or EYES?");
    		
    		//most of your code goes here
    
    	}
    	
    	public void paint(Graphics canvas)
    	{						
    		//Draw face circle:
    		canvas.setColor(Color.YELLOW);
    		canvas.fillOval(X_FACE, Y_FACE, FACE_DIAMETER, FACE_DIAMETER);
    		canvas.setColor(Color.BLACK);
    		canvas.drawOval(X_FACE, Y_FACE, FACE_DIAMETER, FACE_DIAMETER);
    
    		//code to make default color of eyes black
    		if(eyeColor.equalsIgnoreCase(""))
    			canvas.setColor(Color.BLACK);
    
    		// add your code here to change eye color
    
    
    		
    		//You do not have to modify code after this point
    		//Draw eyes:
    		canvas.fillOval(X_RIGHT_EYE, Y_RIGHT_EYE, EYE_WIDTH, EYE_HEIGHT);
    		canvas.fillOval(X_LEFT_EYE, Y_LEFT_EYE, EYE_WIDTH, EYE_HEIGHT);
    		
    					
    		//Draw nose:
    		canvas.setColor(Color.BLACK);
    		canvas.fillOval(xNose, Y_NOSE, noseDiameter, noseDiameter);
    		
    		//Draw mouth:
    		canvas.setColor(Color.RED);
    		canvas.drawArc(X_MOUTH, Y_MOUTH, MOUTH_WIDTH, MOUTH_HEIGHT, mouthStartAngle, MOUTH_DEGREES_SHOWN);
    	}
    }
    I'm supposed to take this code and add in lines to allow the user to modify the mouth, eyes, and nose. I have no idea where to start and would greatly appreciate any help. I know that I need to prompt the user for their specifications, but how do I subsequently use their specifications to modify the resulting image?

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Well, if the FACE_DIAMETER is currently 200, and the user inputs 400... set FACE_DIAMETER to 400 and repaint. Get the idea? Rinse Repeat for each variable!

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Actually FACE_DIAMETER is final. I'm guessing the user can set the value noseDiameter, xNose and friends.

    But yes: obtain the value from the user, then set the value of the corresponding variable.

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

Similar Threads

  1. Ok i am lost
    By jaisan72980 in forum New To Java
    Replies: 3
    Last Post: 01-17-2011, 04:20 AM
  2. lost in labyrinth.
    By niu_niu in forum New To Java
    Replies: 3
    Last Post: 06-10-2010, 12:39 AM
  3. I'm lost :(
    By leonardjr in forum New To Java
    Replies: 8
    Last Post: 03-03-2009, 04:18 AM
  4. So Lost
    By kandt in forum New To Java
    Replies: 5
    Last Post: 12-13-2008, 09:55 PM
  5. Absolutely Lost
    By Lehane_9 in forum New To Java
    Replies: 2
    Last Post: 12-03-2007, 06:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •