Discussion of Activity 7.3 - Designing a logo

Sample solution

1. Code for paintComponent in class OULogo:

 public void paintComponent(Graphics g)
 {
    //U
    g.setColor(Color.blue);
    g.fillRect(X,Y,WIDTH,HEIGHT);
    g.fillArc(X,Y + HEIGHT - WIDTH/2,WIDTH,WIDTH,0,-180);

    //O
    g.setColor(Color.yellow);
    g.fillOval(X + OFFSET,Y + OFFSET,RADIUS,RADIUS);
 }

2. Code for BetterOULogo:

import java.awt.*;
import javax.swing.*;

public class BetterOULogo extends OULogo
{
   public void paintComponent(Graphics g)
   {
      //draw the shadow
      g.setColor(Color.darkGray);
      g.fillArc(X + 10,Y + HEIGHT - WIDTH/2 + 5,WIDTH,WIDTH, 0,-180);
      g.fillRect(X + 10,Y + 5,WIDTH,HEIGHT);

      //draw the logo
      super.paintComponent(g);
   }
}

In this case you will also need to adjust the OULogoTest class so that it passes the PictureFrame class an instance of the BetterOULogo class as follows:

OULogo logo = new BetterOULogo();