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.

Here is a sample program output:

.

Complete the following file:

ThreeButtonComponent.java

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:

ThreeButtonViewer.java

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");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      ThreeButtonComponent component = new ThreeButtonComponent();
      frame.add(component);
      frame.setVisible(true);
   }
}