The part of the object that's in negative coordinate space is not shown. You only see part of the object.
The rectangle is not drawn. It does not appear on the screen.
public Rectangle CircleToRect(Point p, int radius)
which takes as its arguments a java.awt.Point and a radius and returns a java.awt.Rectangle. Before beginning you should review the documentation for points and rectangles at http://www.javasoft.com/JDK-1.0/api/java.awt.Rectangle.html and http://www.javasoft.com/JDK-1.0/api/java.awt.Point.html.
public Rectangle CircleToRect(Point p, int radius) {
Rectangle r = new Rectangle;
int leftmost = p.x - radius;
int topmost = p.y - radius;
int height = 2 * radius;
int width = height;
return new Rectangle(leftmost, topmost, width, height);
}
This is simple. Just set both AppletHeight and AppletWidth to the smaller of the applet's size and width.
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
public class Bullseye extends Applet {
public void paint(Graphics g) {
int RectLeft, RectTop, RectHeight, RectWidth;
int AppletHeight = Math.min(size().height, size().width) ;
int AppletWidth = AppletHeight;
for (int i=8; i >= 0; i--) {
if ((i % 2) == 0) g.setColor(Color.red);
else g.setColor(Color.white);
RectHeight = AppletHeight*i/8;
RectWidth = AppletWidth*i/8;
RectLeft = AppletWidth/2 - i*AppletWidth/16;
RectTop = AppletHeight/2 - i*AppletHeight/16;
g.fillOval(RectLeft, RectTop, RectWidth, RectHeight);
}
}
}