circle



I have been trying to write this circle method that should move the
circle two places of width to the right, the method I have written I get
errors from is below

public void moveRight()

{
moveHorizontal(60);
}




* The class Circle defines a shape with the characteristics of a circle.
*
* xxxxxxxxxxxx
* xxxxxxxxxxxx
*/

public class Circle extends OUAnimatedObject
{
/* Instance variables */

private int diameter;
private CKColour colour;
private int xPos;
private int yPos;



/**
* Constructor for objects of class Circle with the default
characteristics.
*/
public Circle()
{
this.diameter = 20;
this.colour = CKColour.BLUE;
this.xPos = 0;
this.yPos = 0;
}

/* Instance methods */

/**
* Causes execution to pause for 500 milliseconds (half a second).
*/
public void sleep()
{
try
{
Thread.sleep(500);
}
catch (Exception e)
{
System.out.println("Exception has occurred in the sleep()
method");
}
}


/**
* Sets the diameter of the receiver to the value of the argument
aDiameter
*/
public void setDiameter(int aDiameter)
{
this.diameter = aDiameter;
this.update();
}

/**
* Returns the diameter of the receiver.
*/
public int getDiameter()
{
return this.diameter;
}

/**
* Sets the colour of the receiver to the value of the argument
aColour.
*/
public void setColour (CKColour aColour)
{
this.colour = aColour;
this.update();
}

/**
* Returns the colour of the receiver.
*/
public CKColour getColour ()
{
return this.colour;
}

/**
* Sets the horizontal position of the receiver to the value of the
argument x.
*/
public void setXPos(int x)
{
this.xPos = x;
this.update();
}

/**
* Returns the horizontal position of the receiver.
*/
public int getXPos()
{
return this.xPos;
}

/**
* Sets the vertical position of the receiver to the value of the
argument y.
*/
public void setYPos(int y)
{
this.yPos = y;
this.update();
}

/**
* Returns the vertical position of the receiver.
*/
public int getYPos()
{
return this.yPos;
}

/**
* Returns a string representation of the receiver.
*/
public String toString()
{
return "An instance of class "+ this.getClass().getName()
+ ": position (" + this.getXPos() + ", " + this.getYPos()
+ "), diameter " + this.getDiameter() + ", colour " +
this.getColour();
}



/**
* Moves position of receiver two places to the right.
*/
public void moveRight()

{

moveRight (20);

}
.



Relevant Pages

  • Re: getting the graphics context from inside event methods
    ... private Circle circle; ... public void mousePressed{ ... public Circle(int x, int y, int radius, Color color) { ...
    (comp.lang.java.programmer)
  • Re: paintComponent question
    ... E.g. if you want the whole component to be at some arbitrary coordinates ... want to let the user to set the location of the circle by clicking. ... private static class CircleView extends JComponent { ... public void mouseClicked(MouseEvent e) { ...
    (comp.lang.java.gui)
  • Re: Code example for transformation by mouse dragging
    ... > it's new rotational position (in the case of a circle this would be ... class JPanelToDrawOn extends JPanel { ... public void panelMouseReleased{ ... Then each drawableObject needs to implement an interface something like ...
    (comp.lang.java.programmer)
  • Re: graphics dont paint properly - what could be the reason?
    ... >> but the circle does not stay at that position. ... > public class TestContext extends JPanel implements MouseListener { ... > public void mouseReleased{ ... > public Circle(int x, int y, int radius, Color color) { ...
    (comp.lang.java.gui)
  • getting the graphics context from inside event methods
    ... the circle moves with the mouse. ... Because of which, the graphics don't occur. ... public class Circle extends JComponent ... public void removeActionListener( ...
    (comp.lang.java.programmer)