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

    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,;
    lowertorso = new Square(150, 225, 100,;
    armorAccessory = new Circle(200, 175, 60, Color.yellow);

    shoulder = new Circle(125, 155, 40,;
    bicep = new Square(115, 185, 35,;
    forearm = new Square(115, 215, 35,;
    wrist = new Square(115, 250, 35,;
    hand = new Square(115, 285, 35,;

    shoulder2 = new Circle(275, 155, 40,;
    bicep2 = new Square(250, 185, 35,;
    forearm2 = new Square(250, 215, 35,;
    wrist2 = new Square(250, 250, 35,;
    hand2 = new Square(250, 285, 35,;

    hip = new Square(155, 325, 35,;
    thigh = new Square(155, 360, 35,;
    calf = new Square(155, 395, 35,;
    ankle = new Square(155, 430, 35,;
    foot = new Square(155, 465, 35,;

    hip2 = new Square(210, 325, 35,;
    thigh2 = new Square(210, 360, 35,;
    calf2 = new Square(210, 395, 35,;
    ankle2 = new Square(210, 430, 35,;
    foot2 = new Square(210, 465, 35,;

    head = new Circle(200, 90, 30,;


    public void paint(Graphics g)







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


    public void mouseClicked(MouseEvent e) {
    // TODO Auto-generated method stub

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

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


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


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



  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Rep Power

    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