Reputation: 65
I redid the program from the ground up following an example from my textbook on drawing a snowman. It runs and draws my fish, however I'm not sure how to hollow out the tail and the fin ovals with a triangle. (The oval is all yellow, I want to insert a green triangle in each one so it looks like a pacman)
//**********************************************************************
// Fish.Java Louis Colucci
// Draws a fish
//**********************************************************************
import javax.swing.JApplet;
import java.awt.*;
public class Fish extends JApplet
{
public void paint (Graphics page)
{
final int MID = 300;
final int TOP = 100;
setBackground (Color.green);
page.setColor (Color.white);
//Draws the body
page.setColor (Color.blue);
page.fillOval (MID-70, TOP+70, 360, 120);
// Adds the name Jascha Heifetz to the body
page.setColor (Color.black);
page.drawString ("Jascha Heifetz", 365, 240);
//Draws the fin
page.setColor (Color.yellow);
page.fillOval (MID+75, TOP+40, 85, 45);
//Draws the tail
page.setColor (Color.yellow);
page.fillOval (MID+275, TOP+90, 140, 75);
//Draws the eye
page.setColor (Color.yellow);
page.fillOval (MID+0, TOP+100, 12, 12);
//Draws the mouth
page.setColor(Color.white);
page.drawArc (MID-68, TOP+105, 75, 30, 190, 110);
}
}
Upvotes: 0
Views: 6719
Reputation: 324098
Well your basic code is wrong. You should not override the paint() method of a top level container like JApplet (JFrame...). Custom painting is done by overriding the paintComponent() method of a JPanel. Read the section from the Swing tutorial on Custom Painting for more information and working examples.
Then you can check out the tutorial on 2D Graphics for examples of painting different shapes.
Upvotes: 2