import java.awt.*; import java.awt.geom.*; import java.awt.event.*; import javax.swing.*; /** * Code for subclass IncDecPie */ public class IncdecPie extends Incdec { final static double circleSize = 50.; /** * Superclass constructor does most of the work, we finish the job here, * just choose the layout and the order of the 3 widgets */ public IncdecPie () { setLayout (new GridLayout (3, 1)); makeUp (); makeShow (); makeDown (); } /** * Override base class version */ protected void makeShow () { show = new Canvas (this); add (show); // Don't call refreshShow(), first paint callback will call it } /** * Override base class version */ protected void refreshShow () { show.repaint (); } /** * Paint callback from our canvas, passed up to us, * we redraw from our saved value data */ public void drawCanvas (Graphics g) { Graphics2D g2 = (Graphics2D) g; // Outline g2.draw (new Ellipse2D.Double (0., 0., circleSize, circleSize)); // Filled in segment g2.fill (new Arc2D.Double (0., 0., circleSize, circleSize, 0., 360. * (value-min) / (max-min), Arc2D.PIE)); } }