Thus, to display your nascent meter, you
need to augment the MovieApplication
class definition provided in
Segment 702. You add a declaration that declares an
instance variable, meter
, you add an initialization statement that
creates a Meter
instance and assigns that Meter
instance to
the meter
instance variable, and you add an add
statement
that attaches the meter to the center of the content pane. The meter is
created via the two-argument constructor that sets to zero and thirty the
minimum and maximum values shown on the meter .
import javax.swing.*; import java.awt.event.*; public class MovieApplication extends JFrame { public static void main (String argv []) { new MovieApplication("Movie Application"); } // Declare instance variables: private Meter meter; // Define constructor public MovieApplication(String title) { super(title); meter = new Meter(0, 30); getContentPane().add("Center", meter); addWindowListener(new LocalWindowListener()); setSize(350, 150); show(); } // Define window adapter private class LocalWindowListener extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } } }