/** * 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 PANEL ON WHICH THE VERTICAL MONEY SCALE iS DISPLAYED The panel is 45 by 212 pixels. */ import java.awt.*; // for graphics operations (GUI) import javax.swing.*; // swing GUI widgets library public class vert extends JPanel { /*Income scale labels set by HTML tag para- meters viz: as follows: */ private static final String income[][] = { {" £0k","£10k","£20k","£30k","£40k","£50k"}, // value="0" {" £0k"," £5k","£10k","£15k","£20k","£25k"}, // value="1" {" £0k"," £2k"," £4k"," £6k"," £8k","£10k"}, // value="2" {" £0k"," £1k"," £2k"," £3k"," £4k"," £5k"}, // value="3" {" £0k"," £½k"," £1k","£1½k"," £2k","£2½k"}, // value="4" {" £0k","£200","£400","£600","£800"," £1k"}, // value="5" {"£10k"," £0k","£10k","£20k","£30k","£40k"}, // value="6" {"£30k","£20k","£10k"," £0k","£10k","£20k"}, // value="7" {" £0"," £50","£100","£150","£200","£250"}, // value="8" {"£10"," £0","£10","£20","£30","£40"}, // value="9" {"0M","1M","2M","3M","4M","5M"}, // value="10" {"00M","10M","20M","30M","40M","50M"} // value="11" }; private int fh, // font height sf; // monetary scaling factor for vertical axis private static final Font font = new Font("Sans", Font.BOLD, 14); private FontMetrics fm; vert(graphs ap) { // get letter dimensions etc for the above font fm = getFontMetrics(font); // descent of monetary annotation below graduation mark fh = (fm.getAscent() + fm.getDescent()) / 2; // get the monetary scaling factor for vertical axis sf = Integer.valueOf(ap.getParameter("scale")).intValue(); } public void paint(Graphics g) { setFont(font); int z = 6; // vertical graticule increment for(int i = 0; i < 6; i++) { // for each £10,000 graduation if(sf == 6 && i > 4 || sf == 7 && i > 2 || sf == 9 && i > 4) g.setColor(Color.red); // show negative money in red else g.setColor(Color.black); String s = income[sf][5 - i]; // annotation text from top to bottom g.drawString(s, 49 - fm.stringWidth(s), z + 4); g.setColor(Color.black); // all annotation marks are black g.drawLine(50, z, 55, z); // annotation mark z += 40; // accumulated number of £s (scaled) } g.setColor(Color.black); g.drawLine(55,6,55,206); // vertical axis } }