Click to See Complete Forum and Search --> : Circle.java
bobbiesteels
11-11-2003, 01:06 PM
am tryin to implement a java program to draw a circle on a PictureFrame .. i have all the code but just dont know what i have to import .. like with
Rectangle.java
i had this
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Point;
import java.awt.geom.Rectangle2D;
import java.text.ParseException;
import java.util.StringTokenizer;
but i dont know what to use for Circle.java.. i tried
import java.awt.geom.Circle2D .. but it didn't work
try import java.awt.Graphics;
maybe if you post the code it would be more helpful.
I don't really know which libraries you need to import.
bobbiesteels
11-11-2003, 01:30 PM
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Point;
import java.awt.geom.*; ***this is where am havin the problem
import java.text.ParseException;
import java.util.StringTokenizer;
import java.awt.*;
/**
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
public class Circle extends PictureElement {
private Point centre;
private int radius;
/**
* Creates a Circle with the spicified position and dimensions.
*
* @param cent centre of the circle
* @param rad radius of the circle
* @throws IllegalArgumentException if dimensions are invalid
*
*/
public Circle(Point cent, int rad)
{
setCentre(cent);
setRadius(rad);
}
public Circle(Point cent, int rad, String colour)
{
setCentre(cent);
setRadius(rad);
setColour(colour);
}
/**
*
*
*
*
*
*
*
*/
public Circle(StringTokenizer param) throws ParseException
{
int numTokens = param.countTokens();
}
public Point getCentre()
{
return new Point(centre);
}
public int getRadius()
{
return (radius);
}
public void setCentre(Point cent)
{
centre = new Point(cent);
}
public void setRadius(int rad)
{
radius = rad;
}
public String toString()
{
return "Radius = " + radius + " " + super.toString();
}
public void paint(Graphics2D context)
{
// Create a java.awt.geom object to represent rectangle
context =
new Graphics2D.Float(centre.x, centre.y, radius.width, radius.height);
// Paint this rectangle
Paint original = context.getPaint();
context.setPaint(getColour());
context.fill(context);
context.setPaint(original);
}
}
sajchurchey
11-12-2003, 11:56 AM
Check the APIs at http://java.sun.com if you don't remember a class name. Otherwise, what exact error are you getting here? Is there a class not found, or is there a compiler error? My suggestion to you is that there are a lot of redundant imports:
import java.awt.*;
import java.awt.geom.*;
import java.util.StringTokenizer;
import java.text.ParseException;