trouble putting together program for designing catface that will resize in the frame
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import javax.swing.JPanel;
import javax.swing.JComponent;
import javax.swing.JFrame;
import java.util.Random;
import java.awt.geom.Arc2D;
import java.awt.BasicStroke;
/**
* A component that draws a Cat Face.
*@Kevin Bennett
*/
public class CatComponentalt extends JComponent
{
public void paintComponent(Graphics g)
{
// Recover Graphics2D
Graphics2D g2 = (Graphics2D) g;
int w = getWidth();
int h = getHeight();
int size = Math.min(w, h);
// translate the origin to the center of the component.
g2.translate(w / 2, h / 2);
int radius1 = - (int) (2.0 / 11.0 * size);
Rectangle r1 = new Rectangle(w, h);
g2.setColor(Color.YELLOW);
g2.fill(r1);
g2.setColor(Color.BLACK);
// Draw the cat head.
// Ellipse2D.Double head = new Ellipse2D.Double(5, 10, 150, 150);
// g2.translate(200, 200);
g2.draw(radius1);
// Draw the cat head.
//Ellipse2D.Double head = new Ellipse2D.Double(5, 10, 150, 150);
//g2.translate(200, 200);
// Draw the eye number 1.
Ellipse2D.Double eye1 = new Ellipse2D.Double(50, 35, 20, 20);
g2.draw(eye1);
g2.setColor(Color.BLUE);
g2.fill(eye1);
//Line2D.Double eye1 = new Line2D.Double(25, 70, 45, 90);
//g2.draw(eye1);
// Draw the eye number 2.
Ellipse2D.Double eye2 = new Ellipse2D.Double(90, 35, 20, 20);
g2.draw(eye2);
g2.setColor(Color.BLUE);
g2.fill(eye2);
//Line2D.Double eye2 = new Line2D.Double(85, 70, 65, 90);
//g2.draw(eye2);
// Draw the mouth
Arc2D.Double mouth = new Arc2D.Double(65, 110, 60, 60, 90, 90, Arc2D.OPEN);
g2.draw(mouth);
// Draw the Whiskers 1.
Line2D.Double whisker1 = new Line2D.Double(0, 95, 65, 110);
g2.setStroke(new BasicStroke(2));
g2.draw(whisker1);
// Draw the Whiskers 2.
Line2D.Double whisker2 = new Line2D.Double(0, 110, 65, 110);
g2.setStroke(new BasicStroke(2));
g2.draw(whisker2);
// Draw the Whiskers 3.
Line2D.Double whisker3 = new Line2D.Double(0, 125, 65, 110);
g2.setStroke(new BasicStroke(2));
g2.draw(whisker3);
// Draw the Whiskers 4.
Line2D.Double whisker4 = new Line2D.Double(95, 110, 160, 95);
g2.draw(whisker4);
// Draw the Whiskers 5.
Line2D.Double whisker5 = new Line2D.Double(95, 110, 160, 110);
g2.draw(whisker5);
// Draw the Whiskers 6.
Line2D.Double whisker6 = new Line2D.Double(95, 110, 160, 125);
g2.draw(whisker6);
// Draw the Ear 1a
Line2D.Double ear1 = new Line2D.Double(5, 10, 30, 25);
g2.draw(ear1);
// Draw the Ear 1b
Line2D.Double ear2 = new Line2D.Double(5, 10, 20, 40);
g2.draw(ear2);
// Draw the Ear 2a
Line2D.Double ear3 = new Line2D.Double(125, 25, 155, 15);
g2.draw(ear3);
// Draw the Ear 2b
Line2D.Double ear4 = new Line2D.Double(140, 40, 155, 15);
g2.draw(ear4);
// Draw the greeting
g2.setColor(Color.BLUE);
g2.drawString("Hello, Drew", 45, 175);
g2.drawString("Hello, Drew", 45, 200);
}
private void drawRandomCircle(Graphics2D kevin)
{
int w = getWidth();
int h = getHeight();
//Create the head in a random position
Random r = new Random();
final int SIZE = 150; //width and height of the head
// coordinates of top-left corner of bounding box
int x = r.nextInt(w - SIZE);
int y = r.nextInt(h - SIZE);
Ellipse2D.Double head = new Ellipse2D.Double(x, y, SIZE, SIZE);
kevin.setColor(Color.YELLOW);
kevin.fill(head);
}
}
suggestions