/** * 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 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 static final int NumFi[] = {6,6,6,5,1,4,5,7,1,1,1,1}, DEFLT[] = {0,0,0,0,0,2,0,2,0,0,0,0}; private static final String FILES[][] = { // Names of the relevant data files for each view {"inc_me","incwif","incwel","inc_cb","incdla","inctot"}, {"utelec","utgas" ,"utmai" ,"utpho" ,"uttv" ,"uttot" }, {"taxinc","taxni4","taxni1","tax_cc","taxwat","taxtot"}, {"inctot","sp_tax","sp_fix","sp_uti","sp_car"}, {"pppd"}, {"surp3","surp1","surp4","surp2"}, {"fixmor","fixend","fixhse","fixcon","fixtot"}, {"cartax","carins","carpet","carmai","carpkg","carpch","cartot"}, {"elekwh"}, {"utelec"}, {"gaskwh"}, {"utgas"} }, LABLS[][] = { // Button annotations for each view {"My Income","Wife's Income","Welfare (JSA)","Child Benefit", "Disability Living Allowance","Total Family Income"}, {"Electricity","Gas","Boiler Maintenance","Telephone", "Television Licence","Total"}, {"Income Tax","NI Class 4","NI Class 1","Council Tax", "Water Rates","Total Direct Taxation"}, {"A = Gross Income","B = A - all Direct Taxes","C = B - Fixed Costs", "D = C - Utilities Costs","E = D - Car Costs"}, {"Per Person Per Day"}, {"SI on Survival Budget","SI on SB if we had no car", "SI on Degradation Budget","SI on DB if we had no car"}, {"Mortgage Payments","Endowment Policy","House Insurance", "Contents Insurance","Total Fixed Costs"}, {"Road Tax","Car Insurance","Fuel (Petrol)","Maintenance", "Parking Costs","Capital Costs","Total Car Costs"}, {"Electrical Energy"}, {"Electricity Cost"}, {"Thermal Energy (Gas)"}, {"Gas Cost"} }; private String DF = ""; private static int v = 0; // View number private int nf = 7; // maximum number of files available private graphs ap; // instance of the main panel selfile(graphs ap, int v) { this.v = v; // number of the current data view this.ap = ap; // copy instance reference of the loader setLayout(null); // to allow panel to be laid out manually // GET THE NUMBER OF .DAT FILES IN THIS VIEW nf = NumFi[v]; if(nf > 7) nf = 7; // only space for 7 buttons //DEFAULT BUTTON STATES boolean DB[] = {false,false,false,false,false,false,false}; int df = DEFLT[v]; // default file number for this view DB[df] = true; // set specified default radio button ButtonGroup G = new ButtonGroup(); // group for the radio-buttons JRadioButton B[] = new JRadioButton[nf]; // radio-button references for(int i = 0; i < nf; i++) { // for each button in the upper group B[i] = new JRadioButton(LABLS[v][i], DB[i]); // create it G.add(B[i]); // add it to the button group add(B[i]); // add it to the panel B[i].setBounds(0,i*25,240,20); // set its position and size /* Create an event listener for this button and add it to the event handler's list. */ B[i].addItemListener(new graphbut(i,this)); } DF = FILES[v][df]; // set the default data-file } String getDefaultFile(){return DF;} void getData(int i) { // called only by the listener class below if(i < 0 && i >= nf) i = 0; // if selection is within valid range ap.loadData(FILES[v][i]); // trigger loader to get 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 public graphbut(int id, selfile SF) { // construct new checkbox event this.id = id; // set id number pertaining to this instance of 'graphbut' this.SF = SF; // set the reference to the instance of the above class } // from which it came. (only ever one instance anyway). // a checkbox event has occurred from checkbox '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) { /* Using the number of radio-button on whose instance of 'graphbut' this method was invoked, execute the getData() method in the above class. */ switch(id) { 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); } } } }