/** * Current Account Balances: Graphical Display Applet * @author Robert J Morton * @version 12 July 2000, 23 April 2012 * @copyright July 2000 Robert J Morton (all rights reserved) */ /* This applet requires specialised data files called savyyyy.dat (where yyyy is the year number) located in the same directory as savlim1.class and savlim2.class on the web server. It requires no server-side executables or scripts. The data files are generated from input text files by an off-line command-line java program called savlim0.class. This applet conforms to API 1.1 */ import java.awt.*; // for graphics operations (GUI) import javax.swing.*; // swing GUI widgets library public class savlim1 extends JPanel implements Runnable { boolean load = true; // true means "load data file" private Thread T; // reference for a run() thread private graph gp; // instance ref for accounts graph panel private loader ld; // instance ref for loader savlim1(int ls, String cb) { setBackground(new Color(238,238,238)); // set background colour setLayout(null); // to allow the control panels to be laid out manually // Create an instance of each of the following JPanels: maxmin mm = new maxmin(); // max/min balances panel pscale ps = new pscale(); // money scale panel mscale ms = new mscale(); // month scale panel gp = new graph(this,mm,ms); // graph panel selyear sy = new selyear(this,ms,gp); // year selector panel selinfl si = new selinfl(gp); // inflation selector panel // add each to this main panel and set its position and size: add(mm); mm.setBounds(10,0,350,50); add(ps); ps.setBounds(10,56,45,212); add(ms); ms.setBounds(49,268,370,30); add(gp); gp.setBounds(49,62,366,201); add(sy); sy.setBounds(425,40,100,240); add(si); si.setBounds(10,300,350,40); ld = new loader(ls,cb); // create an instance of the data file loader loadData(2000); // display the data initially for the year 2000 T = new Thread(this); // create a run() thread for downloading data T.start(); // start the local run-thread } // MANAGE INTERNET DATA TRANSFERS ON A SEPARATE THREAD public void run() { while(T != null) { // while this thread exists if(load) if(ld.dataLoaded()) { // if hits data all loaded load = false; gp.setD(ld); // pass B[] to the graph panel repaint(); // display the graph } try{Thread.sleep(50);} // sleep then continue loading catch(InterruptedException e){} } } void loadData(int year) { // called by both 'this' and 'selyear' System.out.println("Year: " + year); // string version of the year number e.g. 2001 ld.setFileName("sav" + year + ".dat"); // string version of the year number e.g. 2001 load = true; } }