# Java: Example - Drawing a Face - v2

This simple application creates a graphic component to display a face. It subclasses a `JPanel` and overrides the `paintComponent` method to do the drawing.

      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
    // File: face/PacLadyApplication.java
    // Author: Fred Swartz,  Date: July 1998 ... Oct 2004
    import java.awt.*;
    import javax.swing.*;

    ///////////////////////////////////////////////// class PacLadyApplication
    public class PacLadyApplication {
        public static void main(String[] args) {
            JFrame window = new JFrame("Face"); // Create a new window.
            window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            window.setContentPane(new Face());  // Put drawing in window.
            window.pack();                      // Adjust to fit panel.
            window.setVisible(true);            // Show the window.
        }
    }

    //////////////////////////////////////////////////////////////// class Face
    class Face extends JPanel {
        /** Constructor sets background color and initial size. */
        public Face() {
            this.setPreferredSize(new Dimension(300, 300));
            this.setBackground(Color.GRAY);
        }

        /** Override paintComponent to draw a face */
        public void paintComponent(Graphics g) {
            super.paintComponent(g);   // Required as first line.

            //... Get panel width and height, Compute center.
            int centerX = this.getWidth() / 2;
            int centerY = this.getHeight() / 2;

            //... Draw everything except the mouth in pink
            g.setColor(Color.PINK);
            g.fillArc(centerX-100, centerY-100, 200, 200, 30, 300);

            //... Draw an eye
            g.setColor(Color.MAGENTA);
            g.fillOval(170, 90, 15, 20);
        }
    }

What happens when the window is resized? Can you fix it?