IncdecApp3: Main.java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * Main program for Incdec
 */
public class Main extends JFrame implements ActionListener {
    public static void main (String [] args) {
	java.awt.EventQueue.invokeLater (new Runnable() {
            public void run() {
		new Main ();
            }
        });
    }

    private Incdec id1, id2, id3, id4;

    public Main () {
	// Window setup
	setSize (600, 300);
	setLayout (new FlowLayout());
	setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

	// Create some new Incdec's
	id1 = new IncdecVert ();
	add (id1);

	id2 = new IncdecPie (); //*1 Test the new class, same API
	add (id2); //*1

	id3 = new IncdecVert ();
	add (id3);

	id4 = new IncdecPie ();
	add (id4);

	// And a button to report the data from the Incdec's, for testing
	JButton b = new JButton ("Get data");
	b.addActionListener (this);
	add (b);

	setVisible (true);
    }

    /**
     * Callback from the test button
     */
    public void actionPerformed (ActionEvent e) {
	System.out.println ("Value 1 = " + id1.getValue() + //*1
		", Value 2 = " +  id2.getValue() + //*1
		", Value 3 = " +  id3.getValue() + //*1
		", Value 4 = " +  id4.getValue()); //*1
    }
}
[download file]