Complete the ThreeButtonComponent class to draw three boxes that look like push buttons. Each box is a Rectangle drawn in Color.GRAY using the Graphics2D method fill3DRect. Look in the Graphics2D class API for a complete description of this method. Use true for the value for the boolean raised parameter. (We will learn more about the boolean data type in Chapter 4.) The center of each box has a different colored circle, Color.RED, Color.GREEN, or Color.CYAN.

Complete the following file:

import javax.swing.JComponent; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.Ellipse2D; public class ThreeButtonComponent extends JComponent { public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; // your work here ... } }

Use the following file:

import javax.swing.*;

   Shows a frame with three buttons
public class ThreeButtonViewer
   public static void main(String[] args)
      JFrame frame = new JFrame();
      frame.setSize(270, 200);
      frame.setTitle("Three Button Viewer");
      ThreeButtonComponent component = new ThreeButtonComponent();