Home Segments Top Top Previous Next

750: Mainline

Instead of using the definition of MovieApplication in Segment 726 to test your meter, you can add a main method to the definition of the Meter frame itself. That main method creates a JFrame instance and attaches a meter to that frame. The new main method both displays the meter and tests the meter setters:

import java.awt.*;                               
import javax.swing.*; 
public class Meter extends JComponent implements MeterInterface { 
 // Rest of definition same as in Segment 748 
 public static void main (String argv []) {                         
  JFrame frame = new JFrame("Meter Test");                          
  Meter meter = new Meter(0, 100);                                  
  frame.getContentPane().add("Center", meter);                      
  frame.setSize(350, 150);                                          
  frame.addWindowListener(new ApplicationClosingWindowListener());  
  frame.show();                                                     
  meter.setValue(25);                                               
  meter.setTitle("Meter Test");                                     
 }                                                                  
}