/** * Current Account Balances: Graphical Display Applet * @author Robert J Morton * @version 12 July 2000, 27 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 seltrace extends JPanel { private trace tr; // instance reference of the graph display panel // false: buttons are inactive because it's a non-financial graph private boolean active = true; seltrace(graphs ap, trace tr) { // INSTANCE CONSTRUCTOR this.tr = tr; // graph display panel instance reference setLayout(null); // set for panel to be laid out manually // create a button group for the radio buttons ButtonGroup G = new ButtonGroup(); JRadioButton A = new JRadioButton( "Show the graph as original monetary values.", false ), B = new JRadioButton( "Show the graph inflation-corrected to £Y2k.", true ), C = new JRadioButton( "Show both real and inflation-corrected traces.", false ); if(tr.getScale() > 9) { active = false; // Grey out the buttons if displaying a non-finacial trace A.setForeground(Color.lightGray); B.setForeground(Color.lightGray); C.setForeground(Color.lightGray); } G.add(A); G.add(B); G.add(C); // add them to the button group add(A); add(B); add(C); // add them to this panel A.setBounds(0, 0,500,19); // set their positions and size B.setBounds(0,23,500,19); C.setBounds(0,46,500,19); A.addItemListener(new inflbut(0,this)); // add listerners to them B.addItemListener(new inflbut(1,this)); C.addItemListener(new inflbut(2,this)); } void setTrace(int i){if(active) tr.setTrace(i);} } // LISTENS FOR EVENTS FROM THE YEAR SELECTOR JRadioButtonES class inflbut implements ItemListener { int id; // one of the above events seltrace ST; // the application that called: always the above class // constructor for a new JRadioButton event public inflbut(int id, seltrace ST) { this.id = id; // set the id number of this instance of 'inflbut' this.ST = ST; // set the reference to the instance of the above class } // from which it came. (there is only one instance anyway). // a JRadioButton event has occurred from JRadioButton 'id' public void itemStateChanged(ItemEvent e) { /* To avoid a double pass through setYear(): only act on the mouse release of the button and not on the mouse press. */ if (e.getStateChange() == ItemEvent.SELECTED) { /* Execute the method in the above applet that deals with the radio-button on whose instance of 'seltracelistener' this method was invoked. */ switch(id) { case 0: ST.setTrace(0); break; case 1: ST.setTrace(1); break; case 2: ST.setTrace(2); } } } }