IncdecApp3: IncdecPie.java

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 () { //*1 We override makeShow
	show = new Canvas (this); //*1
	add (show); //*1
	// Don't call refreshShow(), first paint callback will call it
    }

    /**
     * Override base class version
     */
    protected void refreshShow () { //*2 We override refreshShow
	show.repaint (); //*2
    }

    /**
     * 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)); //*3 Draw outline, then filled in segment, using "value"

	// Filled in segment
	g2.fill (new Arc2D.Double (0., 0., circleSize, circleSize, 0., 360. * (value-min) / (max-min), Arc2D.PIE)); //*3
    }
}

[download file]