Write a graphics program that draws your name in red, contained inside a blue rectangle. Provide a class NameViewer and a class NameComponent.

Here is a sample program output:

.

Complete the following file:

NameComponent.java

import javax.swing.JComponent; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; /** Draws a name in red inside a blue rectangle. */ public class NameComponent extends JComponent { public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; . . . } }

Use the following file:

NameViewer.java

import javax.swing.*;

/**
   Shows a frame that draws a name.
 */
public class NameViewer
{
   public static void main(String[] args)
   {
      JFrame frame = new JFrame();

      frame.setSize(300, 100);
      frame.setTitle("NameViewer");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      NameComponent component = new NameComponent();
      frame.add(component);

      frame.setVisible(true);
   }
}