/** * Current Account Balances: Graphical Display Applet * @author Robert J Morton UK-YE572246C * @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; // graph display panel instance reference setLayout(null); // set for panel to be laid out manually // create a button group for the radio buttons ButtonGroup CBI = new ButtonGroup(); // Create the two inflation-correction option radio buttons. JRadioButton CB11 = new JRadioButton("Show actual balances.",true); JRadioButton CB12 = new JRadioButton("Show balances inflation-correct to £Y2K.",false); /* Add them to the radio button group and also to the panel. Then set their respective positions and sizes within the panel. */ CBI.add(CB11); add(CB11); CB11.setBounds(0,0,200,19); CBI.add(CB12); add(CB12); CB12.setBounds(0,20,350,19); // Create and register listeners for them CB11.addItemListener(new selinfllistener(0,this)); 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 inflation-correction button pressed b = true; // set flag to TRUE. gp.setInfl(b); // pass 'inflation-corrected or not' state } // to 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: sets the 'id' number pertaining to this instance of 'selinfllistener' and the reference to the instance of the above class from which it came. (there's only be one instance). */ public selinfllistener(int id, selinfl si) { this.id = id; this.si = si; } // an event has occurred from button 'id' public void itemStateChanged(ItemEvent e) { switch(id) { case 0: si.setInflate(0); break; // not-inflation corrected case 1: si.setInflate(1); // inflation corrected } } }