/** * Bandscope Receiver Applet 1.0.0 [SPECIAL FORMATS CONVERTER] * @author Robert J Morton YE572246C * @version 13 March 2002, 20 March 2012 * @copyright Robert J Morton (all rights reserved) */ import java.awt.*; //f or graphics operations (GUI) class convert { //DRAW A STRING CENTRED AT A HORIZONTAL POSITION x static void centreString(Graphics g, String s, int x, int y) { // Get the dimensions of characters for the current font FontMetrics fm = g.getFontMetrics(); // Compute half width of the string to be displayed int b = (fm.stringWidth(s)) >> 1; g.drawString(s,x - b,y); // display the string } //DRAW A RIGHT-JUSTIFIED STRING static void rightString(Graphics g, String s, int x, int y) { // Get the dimensions of the characters for the current font FontMetrics fm = g.getFontMetrics(); g.drawString(s, x - fm.stringWidth(s),y); // display the string } //INTEGRAL HALF-kHz to DECIMAL MHz STRING static String toMHz( int x, // frequency in integral half-kHz int d // number of decimal places of MHz required ) { int D[] = {5,3,2,1,0}; // to convert decimal places to string chop String s; /* If there's an odd half-kHz, set 4th decimal place of MHz to '5' else if it's a whole number of kHz, set 4th decimal place of MHz to '0'.*/ if((x & 0x1) > 0) s = "5"; else s = "0"; s = "" + (x >> 1) + s; // string of rF in form GL.XXXX MHz int l = s.length(); // insert the decimal point x = l - 4; // to give MHz to 4 decimal places //insert the decimal point and chop to required number of decimal places. s = s.substring(0, x) + "." + s.substring(x, l); return s.substring(0, s.length() - D[d]); } }