import java.awt.*;
import java.awt.geom.*;
public class MeterCanvas extends Canvas {
 String title = "Title to Be Supplied";
 int minValue = 0, maxValue = 30, value = 15;
 // Paint:
 public void paint(Graphics x) {
  Graphics2D g = (Graphics2D) x;                        
  // Obtain Dimension instance and draw:
  Dimension d = getSize(); 
  float meterWidth = d.width * 3 / 4;
  float dialPosition = meterWidth                               
   * (2 * value - maxValue - minValue)                          
     / (2 * (maxValue - minValue));                             
  AffineTransform transform = new AffineTransform();            
  transform.translate(d.width / 2, d.height / 2);               
  g.setTransform(transform);                                    
  GeneralPath p = new GeneralPath();                            
  p.moveTo(- meterWidth / 2, -10);                              
  p.lineTo(- meterWidth / 2, 0);                                
  p.lineTo(meterWidth / 2, 0);                                  
  p.lineTo(meterWidth / 2, -10);                                
  p.moveTo(dialPosition, 0);                                    
  p.lineTo(dialPosition, - 10);                                 
  g.draw(p);                                                    
  // Write title:
  FontMetrics f = g.getFontMetrics();
  int stringWidth = f.stringWidth(title);
  int stringHeight = f.getHeight();
  g.drawString(title, 
               (float)(- stringWidth / 2),                      
               (float)(stringHeight * 2)                        
              );
 }
 // Assist in sizing:
 public Dimension getMinimumSize() {return new Dimension(150, 100);}
 public Dimension getPreferredSize() {return new Dimension(150, 100);}
}
