/** * Iteration Rate Selection Panel for DifEqnAp.class * @author Robert J Morton * @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 { private static final long T[] = { 2000,1000,500,250,100 // update interval choices in millisecs }; 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 // construct the radio button panel selper(difeqnap x, Color pc, int ls) { ap = x; // applet instance setBackground(pc); // set panel colour //lay out items in a single vertical column of 6 setLayout(new GridLayout(6, 0)); // Select annotation language: English or Portuguese String s = "Plot every"; if(ls != 0) s = "Traçar cada"; // Create new label for the above text then add label to this panel. L = new JLabel(s,Label.LEFT); add(L); 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 above radio buttons to this panel, create Item Listeners for then, add them 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)); } void selectPeriod(int i) { Period = T[i]; // set the newly selected period ap.setPeriod(Period); // update the iteration period in main applet } } // 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 public perbut(int id, selper sp) { // constructor for a new checkbox event this.id = id; // set id number pertaining to this instance this.sp = sp; // set the reference to the instance of the class } // from which it came. (there will only be one instance) //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); } } }