/** * Applet to generate a graph of my 'as paid' and my inflation-corrected income. * @author Robert J Morton UK-YE572246C * @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 gener- ated 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 java.applet.*; // all the gubbins to make the applet work import javax.swing.*; // swing GUI widgets library public class graphs extends JApplet implements Runnable { private boolean ready = false, // set true when initialization thread completed jarred = true; // true = applet working from jar file private Thread TH; // reference for a separate run thread private loader LD; // instance reference to the data-loader public void init() { // INITIALISE THE APPLET: Phase 1 of GUI build try { javax.swing.SwingUtilities.invokeAndWait( new Runnable() { public void run() { init1(); } } ); } catch(Exception e) { showStatus("couldn't create Swing GUI"); } } /* SWING INITIALISATION: Since this involves the creation and set-up of Swing widgets, it must be done on the Event Dispatching thread. It is invoked from the applet's init() method above. */ private void init1() { setBackground(new Color(238,238,238)); // set applet's background colour // Get the reference of the content pane of the JApplet Container cp = getContentPane(); cp.setLayout(null); // set the layout mode of the pane to manual. horiz HZ = new horiz(); // Create the 'horizontal scale' panel, cp.add(HZ); // add it to the applet content pane HZ.setBounds(70,225,201,30); // set its position and size vert VT = new vert(this); // Create 'vertical (financial) scale' panel, cp.add(VT); // add it to the applet content pane. VT.setBounds(10,14,56,212); // set its position and size. trace TR = new trace(this,HZ); // Create the 'graph drawing' panel, cp.add(TR); // add it to the applet content pane TR.setBounds(70,20,201,201); // set its position & size within // Create the 'trace selector' (the 3 lower radio buttons) seltrace ST = new seltrace(this,TR); cp.add(ST); // add it to the applet content pane ST.setBounds(10,270,500,75); // set its position and size. // create an instance of the data loader LD = new loader(this, TR, jarred); // Create the 'file selector' (the 7 upper radio buttons) selfile SF = new selfile(this,LD,TR); cp.add(SF); // add it to the applet content pane, SF.setBounds(290,20,240,240); // set its position and size. ready = true; // thread latch = initialization thread finished } /* Start program thread by creating the thread object and starting it running. [returns a call to run()] */ public void start() { TH = new Thread(this); TH.start(); } // MANAGE INTERNET DATA TRANSFERS ON A SEPARATE THREAD public void run() { while(TH != null) { // loop while thread is alive if(ready) LD.runLoop(); // poll the loader's runLoop() /* Put the thread to sleep for 50 milliseconds to allow other events to take place. Catch exceptions while the thread sleeps but do nothing about them because the are notmal GUI or browser events. */ try { TH.sleep(50); } catch (InterruptedException e) { } } } public void stop() { TH = null; } // Stop this program thread }