/** * Iteration Rate Selection Panel for DifEqnAp.class * @author Robert J Morton UK-YE572246C * @version 27 November 1997 modified 07 August 2009, 18 April 2012 */ /* This class contains a group of 5 radio buttons for choosing how often the selected difference equation is iterated and its updated value plotted on the graphs. */ import java.awt.*; // for graphics operations (GUI) import java.awt.event.*; // for the new-fangled 1.1 event handling import javax.swing.*; // library for constructing Swing GUI public class selper extends JPanel { // update interval choices in milliseconds private static final long T[] = {2000, 1000, 500, 250, 100}; private long Period = 100; // currently selected iteration period private difeqnap ap; // instance reference of the main applet private JLabel L; // period selection panel heading label private ButtonGroup G; // to hold the reference for this checkbox group private JRadioButton // to hold the references to a, b, c, d, e; // the individual radio buttons within it selper(difeqnap x, Color pc) { // construct the radio button panel ap = x; // applet instance setBackground(pc); // set panel colour // lay out items in a single vertical column of 6 setLayout(new GridLayout(6, 0)); // Create the Scan Selector's title label, and add it to this panel. L = new JLabel("Plot every:", Label.LEFT); add(L); /* Create a radio button group, then create and add the 5 buttons for selecting the desired iteration period. */ G = new ButtonGroup(); a = new JRadioButton("2 secs", false); G.add(a); b = new JRadioButton("1 sec ", false); G.add(b); c = new JRadioButton("500ms", false); G.add(c); d = new JRadioButton("250ms", false); G.add(d); e = new JRadioButton("100ms", true); G.add(e); /* Add the radio buttons also to this panel, create an Item Listener for each button and add it to the event handler list. */ add(a); a.addItemListener(new perbut(0, this)); add(b); b.addItemListener(new perbut(1, this)); add(c); c.addItemListener(new perbut(2, this)); add(d); d.addItemListener(new perbut(3, this)); add(e); e.addItemListener(new perbut(4, this)); } /* Set the newly-selected iteration period, then up- date the iteration period value in the main applet. */ void selectPeriod(int i) { Period = T[i]; ap.setPeriod(Period); } } // LISTENS FOR EVENTS FROM PERIOD SELECTION BUTTONS class perbut implements ItemListener { int id; //one of the above events selper sp; //the application that called: always the above class /* constructor for a new checkbox event: sets 'id' number pertaining to this instance and the reference to the instance of the class from which it came. (there will only be one instance). */ public perbut(int id, selper sp) { this.id = id; this.sp = sp; } // a checkbox event has occurred from checkbox 'id' public void itemStateChanged(ItemEvent e) { switch(id) { case 0: sp.selectPeriod(0); break; case 1: sp.selectPeriod(1); break; case 2: sp.selectPeriod(2); break; case 3: sp.selectPeriod(3); break; case 4: sp.selectPeriod(4); break; } } }