Results 1 to 2 of 2
  1. #1
    zema109 is offline Member
    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Default Help Creating Mouseclick Events

    I need help with this code. These are my guidelines:

    Create a Person class that draws a person. The Person class should implement the following methods:

    paintComponent with the same signature/header of the other paintComponent methods we have
    written. This will paint the person.
    getNumLeft returns the number of turns the player has left (e.g. 6 at the beginning assuming head,
    body, left/right arm/leg). Hint: this is named like a getter/accessor method for a reason.
    reset which resets the number of turns left and erases the person so it is not visible
    showNext progressively causes the next body part to be shown: head, body, left arm, right arm, left
    leg, right leg
    main a static method used for testing (see Section 4.6). It should display a person object and when
    you click on it the next body part should show, if all parts are visible, then it should be reset so it is no
    longer visible. This will be removed for the final game, but will allow you to test each piece as you go,
    which is a good programming practice. (See the hint below for help with handling the mouse clicking.)

    I wrote some code for the body parts, but I'm having trouble with the getNumLeft and the Mouseclick Events (which will reset once I have all body parts on shown). Also, each mouseclick can be made to show multiple body parts which correspond toimport java.awt.Color;
    import java.awt.Graphics;
    import javax.swing.JApplet;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;


    public class Person extends JApplet implements MouseListener
    {

    private Square torso; // The torso
    private Square lowertorso;
    private Circle armorAccessory;

    private Circle shoulder; //The left arm
    private Square bicep;
    private Square forearm;
    private Square wrist;
    private Square hand;

    private Circle shoulder2; //The left leg
    private Square bicep2;
    private Square forearm2;
    private Square wrist2;
    private Square hand2;

    private Square hip; // The left leg
    private Square thigh;
    private Square calf;
    private Square ankle;
    private Square foot;

    private Square hip2; //The right leg
    private Square thigh2;
    private Square calf2;
    private Square ankle2;
    private Square foot2;



    private Circle head; //Obviously the head
    public int x;

    public void init()
    {
    this.setSize(400, 600);

    torso = new Square(150, 125, 100, Color.green);
    lowertorso = new Square(150, 225, 100, Color.red);
    armorAccessory = new Circle(200, 175, 60, Color.yellow);

    shoulder = new Circle(125, 155, 40, Color.green);
    bicep = new Square(115, 185, 35, Color.green);
    forearm = new Square(115, 215, 35, Color.blue);
    wrist = new Square(115, 250, 35, Color.blue);
    hand = new Square(115, 285, 35, Color.black);

    shoulder2 = new Circle(275, 155, 40, Color.green);
    bicep2 = new Square(250, 185, 35, Color.green);
    forearm2 = new Square(250, 215, 35, Color.blue);
    wrist2 = new Square(250, 250, 35, Color.blue);
    hand2 = new Square(250, 285, 35, Color.black);

    hip = new Square(155, 325, 35, Color.black);
    thigh = new Square(155, 360, 35, Color.blue);
    calf = new Square(155, 395, 35, Color.blue);
    ankle = new Square(155, 430, 35, Color.black);
    foot = new Square(155, 465, 35, Color.black);

    hip2 = new Square(210, 325, 35, Color.black);
    thigh2 = new Square(210, 360, 35, Color.blue);
    calf2 = new Square(210, 395, 35, Color.blue);
    ankle2 = new Square(210, 430, 35, Color.black);
    foot2 = new Square(210, 465, 35, Color.black);

    head = new Circle(200, 90, 30, Color.black);


    }

    public void paint(Graphics g)
    {

    torso.paintComponent(g);
    lowertorso.paintComponent(g);
    armorAccessory.paintComponent(g);

    shoulder.paintComponent(g);
    bicep.paintComponent(g);
    forearm.paintComponent(g);
    wrist.paintComponent(g);
    hand.paintComponent(g);

    shoulder2.paintComponent(g);
    bicep2.paintComponent(g);
    forearm2.paintComponent(g);
    wrist2.paintComponent(g);
    hand2.paintComponent(g);

    hip.paintComponent(g);
    thigh.paintComponent(g);
    calf.paintComponent(g);
    ankle.paintComponent(g);
    foot.paintComponent(g);

    hip2.paintComponent(g);
    thigh2.paintComponent(g);
    calf2.paintComponent(g);
    ankle2.paintComponent(g);
    foot2.paintComponent(g);



    head.paintComponent(g);
    }


    public int getNumLeft()
    {
    return x;
    }
    public void paintComponent(Graphics p) {
    Color tc = p.getColor();

    p.setColor(Color.blue);


    p.setColor(tc);
    }
    @Override
    public void mouseClicked(MouseEvent e) {
    // TODO Auto-generated method stub

    }
    @Override
    public void mouseEntered(MouseEvent e) {
    // TODO Auto-generated method stub

    }
    @Override
    public void mouseExited(MouseEvent e) {
    // TODO Auto-generated method stub

    }


    @Override
    public void mouseReleased(MouseEvent e) {
    // TODO Auto-generated method stub

    }

    @Override
    public void mousePressed(MouseEvent e) {
    // TODO Auto-generated method stub

    }


    }

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

    Default Re: Help Creating Mouseclick Events

    Hello and welcome! Please use [code][/code] tags when posting code so we can easily read it!

    Forum Rules
    Guide For New Members
    BB Code List - Java Programming Forum


    You said you are having some trouble - what trouble? Please be as descriptive as possible.

Similar Threads

  1. getx and gety mouseClick stuff
    By Chozo Knight in forum New To Java
    Replies: 5
    Last Post: 11-22-2010, 03:48 AM
  2. Creating a GUI events with action listeners
    By sidd0123 in forum AWT / Swing
    Replies: 8
    Last Post: 04-02-2010, 11:32 PM
  3. How To Lissen to MouseClick on Combobox.?
    By ocean in forum New To Java
    Replies: 1
    Last Post: 12-04-2009, 07:06 AM
  4. typed events vs untyped events.
    By Drun in forum SWT / JFace
    Replies: 0
    Last Post: 11-23-2009, 12:22 PM
  5. How to make a MouseClick paint an object
    By Devilsfutbol17 in forum New To Java
    Replies: 6
    Last Post: 06-05-2008, 12:54 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
  •