/** * Applet to generate a graph of my 'as paid' and my inflation-corrected income * @author Robert J Morton * @version 18 July 2000, 27 April 2012 * @copyright July 2000 Robert J Morton (all rights reserved) */ /* This applet require a specialised data files called income.dat located in the same directory as income.class and infln.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 income_txtdat.class. This applet conforms to API 1.1 */ import java.awt.*; // for graphics operations (GUI) import javax.swing.*; // swing GUI widgets library public class graphs extends JPanel implements Runnable { private Thread T; // reference for a separate run() thread private loader ld; // instance reference to the data-loader private trace tr; // instance reference to the data-loader private boolean load = true, // load default data file on start loading = false; // true = the requested data is now loaded graphs(int XE, int YE, int ls, String cb, int v) { // CONSTRUCTOR setBounds(0,0,XE,YE); setBackground(new Color(238,238,238)); // set background colour setLayout(null); // allow the control panels to be laid out manually // Create instances of the following classes: horiz hz = new horiz(); // horizontal scale panel selfile sf = new selfile(this,v); // file selector tr = new trace(this,hz,sf,v); // graph drawing panel vert vt = new vert(this,sf,tr); // vertical (financial) scale seltrace st = new seltrace(this,tr); // trace selector (lower 3 radio ld = new loader(ls,cb); // data loader // Add them to this panel and set their positions and sizes add(hz); hz.setBounds(70,225,201,30); add(vt); vt.setBounds(10,14,56,212); add(tr); tr.setBounds(70,20,201,201); add(st); st.setBounds(10,270,500,75); add(sf); sf.setBounds(290,20,240,240); loadData(sf.getDefaultFile()); // load the default file T = new Thread(this); // creating the thread object T.start(); // and starting it running } // MANAGE INTERNET DATA TRANSFERS ON A SEPARATE THREAD public void run() { while(T != null) { // while this thread exists if(load) // if commanded to load a data file loading = true; // a loading process is in operation if(ld.dataLoaded()) { // if data file loaded load = false; // this must be set before setD tr.setD(ld); // pass B[] to the graph panel repaint(); // display the graph loading = false; // the loading process has finished } try{Thread.sleep(50);} // sleep then continue loading catch(InterruptedException e){} } } // LOAD A SPECIFIED DATA FILE void loadData(String fn) { // called by both 'selfile' System.out.println("File: " + fn); ld.setFileName(fn + ".dat"); load = true; } boolean loading(){return loading;} }