/** * Current Account Balances: Graphical Display Applet * @author Robert J Morton * @version 12 July 2000, 23 April 2012 * @copyright July 2000 Robert J Morton (all rights reserved) */ // THE INFLATION-SELECTOR BUTTONS CLASS import java.awt.*; // for graphics operations (GUI) import java.awt.event.*; // for the new-fangled 1.1 event handling import javax.swing.*; // swing GUI widgets library public class selinfl extends JPanel { private graph gp; // instance reference of the graph display panel selinfl(graph gp) { // INSTANCE CONSTRUCTOR this.gp = gp; // display panel instance reference setLayout(null); // set for panel to be laid out manually ButtonGroup CBI = new ButtonGroup(); // create a button group // for the radio buttons /* Create each radio button, add it to the panel so that it is visible, add it also to the button group so that whenever a button is clicked, all the others become automatically de-selected, create an event list- ener for it in order to detect when it is clicked by the mouse. */ JRadioButton CB11 = new JRadioButton("Show actual balances.",true); add(CB11); CBI.add(CB11); CB11.setBounds(0,0,200,19); CB11.addItemListener(new selinfllistener(0,this)); JRadioButton CB12 = new JRadioButton("Show balances inflation-correct to £Y2K.", false); add(CB12); CBI.add(CB12); CB12.setBounds(0,20,350,19); CB12.addItemListener(new selinfllistener(1,this)); } // set whether to show actual or inflation-corrected graphs void setInflate(int x) { boolean b = false; // assume non-inflation-corrected if(x > 0) // But if the inflation-correction b = true; // button was pressed, set true. gp.setInfl(b); // Pass the 'inflation-corrected } // or not' state to the graph panel. } // LISTENS FOR EVENTS FROM INFLATION SELECTOR BUTTONS class selinfllistener implements ItemListener { int id; // one of the above events selinfl si; // the application that called: always the above class // constructor for a new item listener public selinfllistener(int id, selinfl si) { this.id = id; // set id number of this instance of 'selinfllistener' this.si = si; // set the reference to the instance of the above class } // from which it came. (only one instance anyway). // an event has occurred from button 'id' public void itemStateChanged(ItemEvent e) { switch(id) { case 0: si.setInflate(0); // not-inflation corrected button pressed break; case 1: si.setInflate(1); // inflation corrected button pressed } } }