/** * 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 FILE-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 selfile extends JPanel { private boolean //which buttons are required BR[] = {false,false,false,false,false,false,false}; private String BL[] = {"label0","label1","label2","label3","label4","label5","label6"}, DF[] = {"file0", "file1", "file2", "file3", "file4", "file5", "file6"}, FN; // filename of current data file private int NB = 7, // total number of buttons (max is 10) nf = 7; // number of files available private loader LD; // instance reference of the loader selfile(graphs ap, loader LD, trace TR) { this.LD = LD; // copy instance reference of the loader setLayout(null); // to allow the control panels to be laid out manually // GET THE NUMBER OF .DAT FILES FROM HTML PARAMETER nf = Integer.valueOf(ap.getParameter("files")).intValue(); if(nf > 7) nf = 7; // only room for 7 buttons // GET THE SCALING FACTOR INDEX NUMBER FROM THE HTML PARAMETER int sf = Integer.valueOf(ap.getParameter("scale")).intValue(); if(sf > 9) // If a non-money scale were specified, TR.setTrace(0); // show only the main (non-inflation-corrected) trace else // otherwise TR.setTrace(1); // show only the inflation-corrected trace by default. for(int i = 0; i < nf; i++) { // For each of the required traces, DF[i] = ap.getParameter(DF[i]); // get name of its data file, BL[i] = ap.getParameter(BL[i]); // substitute the required button label BR[i] = true; // and set up which buttons are } // required in upper group. //DEFAULT BUTTON STATES boolean DB[] = {false,false,false,false,false,false,false}; try { // Try to get the specified default radio button int df = Integer.valueOf(ap.getParameter("default")).intValue(); DB[df] = true; // and set it and FN = DF[df]; // its data name as the default. } catch(Exception e) { // if default button parameter is not present DB[nf - 1] = true; // set the last radio button FN = DF[nf - 1]; // and the data name as default } // Create a radio button group and an array for radio button references ButtonGroup G = new ButtonGroup(); JRadioButton B[] = new JRadioButton[NB]; for(int i = 0; i < NB; i++) // For each button in the upper group if(BR[i]) { // if button required for this instance of graph B[i] = new JRadioButton(BL[i], DB[i]); G.add(B[i]); // add it to the button group add(B[i]); // and to the panel // and set its position and size within the panel B[i].setBounds(0,i * 25,240,20); /* create an event listener for it and add the listener to the event handler list */ B[i].addItemListener(new graphbut(i,this)); } LD.getData(DF[nf - 1]); // trigger loading of the default data-file } void getData(int i) { // Called only by the listener class below: if(i > -1 && i < nf) // Provided the selection is within the valid range LD.getData(DF[i]); // trigger the loader to get the selected file. } } // LISTENS FOR EVENTS FROM THE FILE SELECTOR BUTTONS class graphbut implements ItemListener { int id; // one of the above events selfile SF; // the application that called: always the above class /* Constructor for a new checkbox event: sets the 'id' number pertaining to this instance of 'graphbut' and the reference to the instance of the above class from which it came. (only one instance anyway). */ public graphbut(int id, selfile SF) { this.id = id; this.SF = SF; } // a checkbox event has occurred from checkbox 'id' public void itemStateChanged(ItemEvent e) { switch(id) { /* Using the number of radio-button on whose instance of 'graphbut' this method was invoked, execute the getData() method in the above class. */ case 0: SF.getData(0); break; case 1: SF.getData(1); break; case 2: SF.getData(2); break; case 3: SF.getData(3); break; case 4: SF.getData(4); break; case 5: SF.getData(5); break; case 6: SF.getData(6); break; } } }