/** * 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 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 { private static final String // ANNOTATION TEXT FROM TOP TO BOTTOM AT[][] = { // £ scale labels {" £0k","£10k","£20k","£30k","£40k","£50k"}, // scale = 0 {" £0k"," £5k","£10k","£15k","£20k","£25k"}, // 1 {" £0k"," £2k"," £4k"," £6k"," £8k","£10k"}, // 2 {" £0k"," £1k"," £2k"," £3k"," £4k"," £5k"}, // 3 {" £0k"," £½k"," £1k","£1½k"," £2k","£2½k"}, // 4 {" £0k","£200","£400","£600","£800"," £1k"}, // 5 {"£10k"," £0k","£10k","£20k","£30k","£40k"}, // 6 {"£30k","£20k","£10k"," £0k","£10k","£20k"}, // 7 {" £0"," £50","£100","£150","£200","£250"}, // 8 { "£10"," £0", "£10", "£20", "£30", "£40"}, // 9 { "0M", "1M", "2M", "3M", "4M", "5M"}, // 10 { "00M", "10M", "20M", "30M", "40M", "50M"} // 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, selfile SF, trace tr) { // 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 = tr.getScale(); } 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 = AT[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 } }