/** * Equation Selector for CtrlPanl.class re DifEqnAp.class * @author Robert J Morton * @version 27 November 1997 modified 07 August 2009, 18 April 2012 */ /* This class contains a pair of radio buttons for choosing which of the two difference equations to iterate: x = x**2 + c or x = cx(1 - x) */ 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 seleqn extends JPanel { private cval sc; // reference to the c value text entry panel private timegr tg; // reference to time-graph instance private bouncegr bg; // reference to bounce-graph instance private formula f; // instance reference to formula class private JLabel L; // reference for the title label private ButtonGroup G; // reference for the checkbox group private JRadioButton a, b; // references for the two buttons private int ls = 0; // language switch: 0=English 1=Portuguese private String s; // for multi-language private boolean Flags[] = {false,true}, // the two flag options EqnFlag = false; /* false means x = cx(1 - x) is selected true means x = x**2 + c is selected */ seleqn(cval sc, timegr tg, bouncegr bg, formula f, Color pc, int ls) { this.sc = sc; // set instance ref. of cval class to local variable this.tg = tg; // set instance ref. of timegr class to local variable this.bg = bg; // set instance ref. of bouncegr class to local variable this.f = f; // set instance ref. of formula class to local variable this.ls = ls; // language switch setBackground(pc); // set panel colour setLayout( new GridLayout(3,0) // lay out the 3 objects one beneath the next ); s = "Equation"; // English/Portuguese if(ls != 0) s = "Equação"; L = new JLabel(s,Label.LEFT); // create equation selector panel label add(L); // add it to this panel G = new ButtonGroup(); // group container for radio buttons a = new JRadioButton("x = cx(1 - x)",true); G.add(a); // add it to the button-group add(a); // add it to this panel a.addItemListener(new eqnbut(0,this)); // create Item Listener for it b = new JRadioButton("x = x * x + c",false); G.add(b); // add it to the button-group add(b); // add it to this panel b.addItemListener(new eqnbut(1,this)); // create Item Listener for it } void selectEquation(int i) { EqnFlag = Flags[i]; // set new state of the equation selector f.setEF(EqnFlag); // set equation-flag state in formula class tg.setEF(EqnFlag); // set equation-flag state in time-graph class bg.setEF(EqnFlag); // set equation-flag state in bounce-graph class sc.setEF(EqnFlag); // set equation-flag state in C-value class sc.initCval(); // reset c to default value for selected equation } } // LISTENS FOR EVENTS FROM EQUATION SELECTION BUTTONS class eqnbut implements ItemListener { int id; // one of the above events seleqn se; // the application that called: always the above class // constructor for a new checkbox event public eqnbut(int id, seleqn se) { this.id = id; // set id number pertaining to this instance this.se = se; // set reference to the instance of above class } // from which it came. // event has occurred from checkbox 'id' public void itemStateChanged(ItemEvent e) { switch(id) { case 0: se.selectEquation(0); break; // equation x = cx(1 - x) selected case 1: se.selectEquation(1); // equation x = x**2 + c selected } } }