import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* Main program for Incdec
*/
public class Main 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; //*1 Use polymorphism
public Main () {
// Window setup
JFrame frame = new JFrame();
frame.setSize (700, 300);
frame.setLayout (new FlowLayout());
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
// Create some new Incdec's
id1 = new IncdecVert (); //*2 Add() both kinds just like a standard widget
frame.add (id1); //*2
id2 = new IncdecHor (); //*2
frame.add (id2); //*2
id3 = new IncdecVert (); //*2
frame.add (id3); //*2
id4 = new IncdecHor (); //*2
frame.add (id4); //*2
// And a button to report the data from the Incdec's, for testing
JButton b = new JButton ("Get data");
b.addActionListener (this);
frame.add (b);
frame.setVisible (true);
}
/**
* Callback from the test button
*/
public void actionPerformed (ActionEvent e) {
System.out.println ("Value 1 = " + id1.getValue() +
", Value 2 = " + id2.getValue() +
", Value 3 = " + id3.getValue() +
", Value 4 = " + id4.getValue());
}
}