/** * Current Account Balances: Graphical Display Applet * @author Robert J Morton UK-YE572246C * @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 ); // grey-out the buttons if displaying a non-finacial trace if(Integer.valueOf(ap.getParameter("scale")).intValue() > 9) { active = false; 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 checkbox event: sets the 'id' number pertain- ing to this instance of 'graphbut' and the reference to the instance of the above class from which it came. (only one instance anyway). */ public inflbut(int id, seltrace ST) { this.id = id; this.ST = ST; } // a JRadioButton event has occurred from JRadioButton 'id' public void itemStateChanged(ItemEvent e) { switch(id) { case 0: ST.setTrace(0); break; case 1: ST.setTrace(1); break; case 2: ST.setTrace(2); break; } } }