import javax.swing.*; import java.awt.*; import java.awt.event.*; /**** * * Pop-up window to display the area of the currently selected shape. * */ public class AreaDialog extends JOptionPane implements ActionListener { /** The workspace model. */ WorkSpace workSpace; /** Message prefix */ String prefix = "Area of selected shape = "; /** * Construct with the given workspace. */ public AreaDialog(WorkSpace workSpace) { this.workSpace = workSpace; } /** * Respond to the actionPeformed, which comes from the menu item selection. */ public void actionPerformed(ActionEvent e) { Shape selection = workSpace.getSelection(); if (selection != null) { showMessageDialog(null, prefix + (new Double(selection.getArea())).toString()); } else { showMessageDialog(null, "No shape selected.", "", JOptionPane.ERROR_MESSAGE); } } }