Results 1 to 2 of 2
  1. #1
    yanalvine is offline Member
    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0

    Post i cant get the sad face need to change sad code part

    import java.awt.*;
    import java.applet.Applet;
    import java.awt.event.*;

    public class Smiley extends Applet implements ActionListener
    {
    /**
    *
    */
    private static final long serialVersionUID = 1L;
    private boolean SMILE = true;
    private final Font f = new Font("Helvetica", Font.PLAIN, 9);

    public void init() { // Define the GUI

    // The applet has a "Smile" button
    final Button smileButton = new Button("Smile"); // create button
    add(smileButton); // add to applet's GUI
    smileButton.addActionListener(this); // register event listener

    // The applet has a "Sad" button
    final Button sadButton = new Button("Sad");
    add(sadButton);
    sadButton.addActionListener(this);

    // set initial background
    setBackground(Color.lightGray);

    } // end of init

    public void actionPerformed(final ActionEvent e) { // The event handler

    // Get the command (which button was pressed?)
    final String cmd = e.getActionCommand();

    if (cmd.equals("Smile")) { // "Smile" was pressed
    SMILE = true;
    setBackground(Color.lightGray);
    repaint();
    }
    else if (cmd.equals("Sad")) { // "Sad"
    SMILE = false;
    setBackground(Color.lightGray);
    repaint();
    }

    } // end of actionPerformed


    public void paint( final Graphics g ) {
    // draw the face

    g.setColor( Color.YELLOW );
    g.fillOval( 10, 10, 200, 200 );



    // draw the eyes

    g.setColor( Color.BLACK );
    g.fillOval( 55, 65, 30, 30 );

    // draw the mouth

    g.fillOval( 135, 65, 30, 30 );
    g.fillOval( 50, 110, 120, 60 );



    // Draw smiley or sad
    if (SMILE) {

    // "touch up" the mouth into a smile
    g.setColor( Color.YELLOW );
    g.fillRect( 50, 110, 120, 30 );
    g.fillOval( 50, 120, 120, 40 );

    }
    else {
    // "touch up" the mouth into a smile to get sad face
    g.setColor( Color.YELLOW );
    g.fillRect( 50, 110, 120, 30 );
    g.fillOval( 50, 120, 120, 40 );
    }

    // SIGNATURE: Write signature
    g.setFont(f);
    g.drawString("Applet by Deepak.", 1, 199);
    } // end of paint
    } // end of class Smiley
    Last edited by yanalvine; 10-21-2013 at 05:54 AM.

  2. #2
    yanalvine is offline Member
    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0

    Default Re: i cant get the sad face need to change sad code part

    please that the the touch up part i cant change to get a sad face can someone help?

    // "touch up" the mouth into a smile
    g.setColor( Color.YELLOW );
    g.fillRect( 50, 110, 120, 30 );
    g.fillOval( 50, 120, 120, 40 );

Similar Threads

  1. need help understanding part of code
    By mustachMan in forum New To Java
    Replies: 7
    Last Post: 02-09-2011, 08:11 PM
  2. Sychronizing a part of a code in a method
    By SarahB in forum Threads and Synchronization
    Replies: 1
    Last Post: 01-03-2010, 11:22 PM
  3. Trouble implementing part of code into GUI
    By Flaresplitz in forum New To Java
    Replies: 1
    Last Post: 12-21-2008, 08:51 AM

Tags for this Thread

Posting Permissions

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