import java.awt.*; import java.applet.*; import java.awt.event.*; import java.lang.*; /** * This class (applet) models a ft-inch-sixteenth calculator */ public class calculator extends Applet implements ActionListener, ItemListener { /** * called when the foot button is depressed * * footButton can only be called once when entering a number - this method * checks this automatically */ public calculator ( ) { } /** * when the foot button is depressed */ private void footButton ( ) { // verify that the foot button has not been pressed if ( this.ft_pressed == false ) { // tell the program that the foot button has been pressed this.ft_pressed = true; // update the display to indicate this this.display.setText ( this.addFoot( this.display.getText() ) ); this.enableFeet(); } } /** * perform an addition operation */ private void addButton ( ) { this.resetFlags(); // perform the operation this.performOperation( this.cvtDisplay ( this.display.getText() ) , this.ADD ); // output the result this.display.setText( this.getResult() ); } /** * perform a end result */ private void eqButton ( ) { this.resetFlags(); // output the result this.performOperation( this.cvtDisplay ( this.display.getText() ) , this.INITIAL ); this.display.setText( this.getResult() ); } /** * perform a subtraction operation */ private void subButton ( ) { this.resetFlags(); // perform the operation this.performOperation( this.cvtDisplay( this.display.getText() ) , this.SUB ); // output the result this.display.setText( this.getResult() ); } /** * perform a multiplication operation */ private void mulButton ( ) { this.resetFlags(); // perform the operation this.performOperation( this.cvtDisplay ( this.display.getText() ) , this.MUL ); // output the result this.display.setText( this.getResult() ); } /** * perform a division operation */ private void divButton ( ) { this.resetFlags(); // perform the operation this.performOperation( this.cvtDisplay ( this.display.getText() ) , this.DIV ); // output the result this.display.setText( this.getResult() ); } /** * clear button returns the calculator to the initial state */ private void clearButton ( ) { // set all of the flags to false this.resetFlags(); // reset the display this.opBuffer1 = 0; this.display.setText( this.getResult() ); this.operation1 = this.ADD; } /** * decimal button */ private void decButton ( ) { if ( ! this.decPressed ) { this.decPressed = true; if ( this.operation || this.initState ) this.display.setText( "0." ); else this.display.setText( display.getText() + "." ); } if ( this.initState ) this.initState = false; } /** * called whenever a numeric button is pressed * * logic in numeric button: * user enters a sequence of integers representing feet until he selects * an operation ( see operation logic ), or the foot symbol. When he selects * the foot symbol, a switch indicates this */ private void numericButton ( int i ) { // if someone previously hit an operation button if ( this.operation ) { // acknowledge and reset operation this.operation = false; // clear the display if ( ! this.decPressed ) this.display.setText( "" ); else this.display.setText( this.display.getText() ); } // a string to hold the current display String display = this.display.getText(); // if the calc has been cleared or is in initial state - ready for input // can only accept 0-9 until foot has been pressed if ( this.initState && this.ft_pressed == false && i <= 9 && i >= 0 && ! this.decPressed ) { this.display.setText( "" + i ); } // if the user is continuing to enter feet - feet must not be pressed and // digits can only be 1- 9 else if ( this.ft_pressed == false && i <=9 && i >= 0 ) { this.display.setText( display + i ); } // if the calculators ft has been pressed, then we are gathering either 1 or // 2 more keystrokes - the first can be 0 - 11 else if ( this.ft_pressed == true && this.inch_pressed == false && this.sixTeenth_pressed == false && i >= 0 && i <= 11 ){ // if this.inch == false, then this is the keystroke which is selecting // an inch if ( this.inch_pressed == false ) this.inch_pressed = true; this.display.setText ( this.addInch( this.display.getText(), "" + i ) ); } else if ( this.ft_pressed == true && this.inch_pressed == true && i >= 0 && i <= 15 ){ // if this.inch == false, then this is the keystroke which is selecting // an inch if ( this.inch_pressed == false ) this.inch_pressed = true; this.display.setText ( this.addSixteenth ( this.display.getText(), "" + i ) ); // set flag so we don't allow any more input this.maxPressed = true; } if ( this.inch_pressed == true ) { this.enableSixteenths ( ); } if ( this.initState ) { this.initState = false; } } /** * start the program */ public void init(){ GridBagLayout gridbag = new GridBagLayout ( ); GridBagConstraints constraints = new GridBagConstraints ( ); setLayout ( gridbag ); // display - spans 4 cells and one column buildConstraints ( constraints, 0, 0, 4, 1, 0, 12 ); // stretches the component to fill both directions constraints.fill = GridBagConstraints.BOTH; this.display = new TextField( this.initOutput ); gridbag.setConstraints( display, constraints ); this.add ( display ); CheckboxGroup group = new CheckboxGroup ( ); buildConstraints ( constraints, 0, 1, 2, 1, 50, 12 ); constraints.fill = GridBagConstraints.CENTER; this.dec_but = new Checkbox ( "DEC", group, false ); gridbag.setConstraints( this.dec_but, constraints ); this.dec_but.addItemListener( this ); add ( this.dec_but); buildConstraints ( constraints, 2, 1, 2, 1, 50, 0 ); constraints.fill = GridBagConstraints.CENTER; this.ft_in_but = new Checkbox ( "FT-IN", group, false ); gridbag.setConstraints( this.ft_in_but, constraints ); this.ft_in_but.addItemListener( this ); add ( this.ft_in_but ); this.ft_in_but.setState(true); // 13 button buildConstraints ( constraints, 0, 2, 1, 1, 25, 12 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_13 = new Button ( "13" ); gridbag.setConstraints( b_13, constraints ); this.b_13.addActionListener( this ); this.b_13.setEnabled( false ); this.b_13.setBackground( Color.white ); add ( this.b_13 ); // 14 button buildConstraints ( constraints, 1, 2, 1, 1, 25, 0 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_14 = new Button ( "14" ); gridbag.setConstraints( b_14, constraints ); this.b_14.addActionListener( this ); this.b_14.setEnabled( false ); this.b_14.setBackground( Color.white ); add ( b_14 ); // 15 button buildConstraints ( constraints, 2, 2, 1, 1, 25, 0 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_15 = new Button ( "15" ); gridbag.setConstraints( b_15, constraints ); this.b_15.addActionListener( this ); this.b_15.setEnabled( false ); this.b_15.setBackground( Color.white ); add ( b_15 ); // clear button buildConstraints ( constraints, 3, 2, 1, 1, 25, 0 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_clr = new Button ( "Cl" ); gridbag.setConstraints( this.b_clr, constraints ); this.b_clr.addActionListener( this ); this.b_clr.setBackground( Color.white ); add ( this.b_clr ); // 10 button buildConstraints ( constraints, 0, 3, 1, 1, 0, 12 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_10 = new Button ( "10" ); gridbag.setConstraints( b_10, constraints ); this.b_10.addActionListener( this ); this.b_10.setEnabled( false ); this.b_10.setBackground( Color.white ); add ( b_10 ); // 11 button buildConstraints ( constraints, 1, 3, 1, 1, 0, 0 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_11 = new Button ( "11" ); gridbag.setConstraints( b_11, constraints ); this.b_11.addActionListener( this ); this.b_11.setEnabled( false ); this.b_11.setBackground( Color.white ); add ( b_11 ); // 12 button buildConstraints ( constraints, 2, 3, 1, 1, 0, 0 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_12 = new Button ( "12" ); gridbag.setConstraints( b_12, constraints ); this.b_12.addActionListener( this ); this.b_12.setEnabled( false ); this.b_12.setBackground( Color.white ); add ( b_12 ); // divide button buildConstraints ( constraints, 3, 3, 1, 1, 0, 0 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_div = new Button ( " /" ); gridbag.setConstraints( this.b_div, constraints ); this.b_div.addActionListener( this ); this.b_div.setBackground( Color.white ); add ( this.b_div ); // 7 button buildConstraints ( constraints, 0, 4, 1, 1, 0, 12 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_7 = new Button ( " 7" ); gridbag.setConstraints( b_7, constraints ); this.b_7.addActionListener( this ); this.b_7.setBackground( Color.white ); add ( b_7 ); // 8 button buildConstraints ( constraints, 1, 4, 1, 1, 0, 0 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_8 = new Button ( " 8" ); gridbag.setConstraints( b_8, constraints ); this.b_8.addActionListener( this ); this.b_8.setBackground( Color.white ); add ( b_8 ); // 9 button buildConstraints ( constraints, 2, 4, 1, 1, 0, 0 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_9 = new Button ( " 9" ); gridbag.setConstraints( b_9, constraints ); this.b_9.addActionListener( this ); this.b_9.setBackground( Color.white ); add ( b_9 ); // mult button buildConstraints ( constraints, 3, 4, 1, 1, 0, 0 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_mul = new Button ( " *" ); gridbag.setConstraints( this.b_mul, constraints ); this.b_mul.addActionListener( this ); this.b_mul.setBackground( Color.white ); add ( this.b_mul ); // 4 button buildConstraints ( constraints, 0, 5, 1, 1, 0, 12 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_4 = new Button ( " 4" ); gridbag.setConstraints( b_4, constraints ); this.b_4.addActionListener( this ); this.b_4.setBackground( Color.white ); add ( b_4 ); // 5 button buildConstraints ( constraints, 1, 5, 1, 1, 0, 0 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_5 = new Button ( " 5" ); gridbag.setConstraints( b_5, constraints ); this.b_5.addActionListener( this ); this.b_5.setBackground( Color.white ); add ( b_5 ); // 6 button buildConstraints ( constraints, 2, 5, 1, 1, 0, 0 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_6 = new Button ( " 6" ); gridbag.setConstraints( b_6, constraints ); this.b_6.addActionListener( this ); this.b_6.setBackground( Color.white ); add ( b_6 ); // minus button buildConstraints ( constraints, 3, 5, 1, 1, 0, 0 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_sub = new Button ( " -" ); this.b_sub.addActionListener( this ); gridbag.setConstraints( this.b_sub, constraints ); this.b_sub.setBackground( Color.white ); add ( this.b_sub ); // 1 button buildConstraints ( constraints, 0, 6, 1, 1, 0, 12 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_1 = new Button ( " 1" ); this.b_1.addActionListener( this ); gridbag.setConstraints( b_1, constraints ); this.b_1.setBackground( Color.white ); add ( b_1 ); // 2 button buildConstraints ( constraints, 1, 6, 1, 1, 0, 0 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_2 = new Button ( " 2" ); gridbag.setConstraints( b_2, constraints ); this.b_2.addActionListener( this ); this.b_2.setBackground( Color.white ); add ( b_2 ); // 3 button buildConstraints ( constraints, 2, 6, 1, 1, 0, 0 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_3 = new Button ( " 3" ); gridbag.setConstraints( b_3, constraints ); this.b_3.addActionListener( this ); this.b_3.setBackground( Color.white ); add ( b_3 ); // add button buildConstraints ( constraints, 3, 6, 1, 1, 0, 0 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_add = new Button ( " +" ); gridbag.setConstraints( this.b_add, constraints ); this.b_add.addActionListener( this ); this.b_add.setBackground( Color.white ); add ( this.b_add ); // 0 button buildConstraints ( constraints, 0, 7, 1, 1, 0, 12 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_0 = new Button ( " 0" ); gridbag.setConstraints( b_0, constraints ); this.b_0.addActionListener( this ); this.b_0.setBackground( Color.white ); add ( b_0 ); // ft button buildConstraints ( constraints, 1, 7, 1, 1, 0, 0 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_ft = new Button ( " '" ); gridbag.setConstraints( b_ft, constraints ); this.b_ft.addActionListener( this ); this.b_ft.setBackground( Color.white ); add ( b_ft ); // decimal button buildConstraints ( constraints, 2, 7, 1, 1, 0, 0 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_dec = new Button ( " ." ); this.b_dec.addActionListener( this ); gridbag.setConstraints( this.b_dec, constraints ); this.b_dec.setEnabled( false ); this.b_dec.setBackground( Color.white ); add ( this.b_dec ); // eq button buildConstraints ( constraints, 3, 7, 1, 1, 0, 0 ); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; this.b_eq = new Button ( " =" ); this.b_eq.addActionListener( this ); gridbag.setConstraints( this.b_eq, constraints ); this.b_eq.setBackground( Color.white ); add ( this.b_eq ); // change the fonts of the buttons from the default settings Font f = new Font ( "Courier", Font.BOLD, 14 ); this.b_0.setFont( f ); this.b_1.setFont( f ); this.b_10.setFont( f ); this.b_11.setFont( f ); this.b_12.setFont( f ); this.b_13.setFont( f ); this.b_14.setFont( f ); this.b_15.setFont( f ); this.b_2.setFont( f ); this.b_3.setFont( f ); this.b_4.setFont( f ); this.b_5.setFont( f ); this.b_6.setFont( f ); this.b_7.setFont( f ); this.b_8.setFont( f ); this.b_9.setFont( f ); this.b_add.setFont( f ); this.b_clr.setFont( f ); this.b_div.setFont( f ); this.b_eq.setFont( f ); this.b_ft.setFont( f ); this.b_dec.setFont( f ); this.b_sub.setFont( f ); this.b_mul.setFont( f ); this.display.setText( this.getResult( ) ); this.setBackground( Color.lightGray ); this.clearButton(); } /** * changes the operation of the calculator - Decimal or Ft-In-16th mode */ public void itemStateChanged ( ItemEvent evt ) { Object source = evt.getSource(); if ( source == this.ft_in_but ) { this.b_dec.setEnabled( false ); this.b_ft.setEnabled( true ); this.resetFlags(); this.modeDecimal = false; this.display.setText( this.getResult() ); } if ( source == this.dec_but ) { this.b_ft.setEnabled( false ); this.b_dec.setEnabled( true ); this.resetFlags(); this.modeDecimal = true; this.display.setText( this.opBuffer1 + "" ); } } /** * directs the flow of the program based on which key was pressed */ public void actionPerformed ( ActionEvent event ) { Object src = event.getSource(); // perform the operation of the key which was pressed if ( src == this.b_0 && this.maxPressed == false ){ this.numericButton( 0 ); } else if ( src == this.b_1 && this.maxPressed == false ) { this.numericButton( 1 ); } else if ( src == this.b_2 && this.maxPressed == false ) { this.numericButton( 2 ); } if ( src == this.b_3 && this.maxPressed == false ){ this.numericButton( 3 ); } else if ( src == this.b_4 && this.maxPressed == false ) { this.numericButton( 4 ); } else if ( src == this.b_5 && this.maxPressed == false ) { this.numericButton( 5 ); } if ( src == this.b_6 && this.maxPressed == false ){ this.numericButton( 6 ); } else if ( src == this.b_7 && this.maxPressed == false ) { this.numericButton( 7 ); } else if ( src == this.b_8 && this.maxPressed == false ) { this.numericButton( 8 ); } if ( src == this.b_9 && this.maxPressed == false ){ this.numericButton( 9 ); } else if ( src == this.b_10 && this.maxPressed == false ) { this.numericButton( 10 ); } else if ( src == this.b_11 && this.maxPressed == false ) { this.numericButton( 11 ); } if ( src == this.b_12 && this.maxPressed == false ){ this.numericButton( 12 ); } else if ( src == this.b_13 && this.maxPressed == false ) { this.numericButton( 13 ); } else if ( src == this.b_14 && this.maxPressed == false ) { this.numericButton( 14 ); } if ( src == this.b_15 && this.maxPressed == false ){ this.numericButton( 15 ); } if ( src == this.b_ft && this.maxPressed == false && this.operation == false && this.dec_but.getState() == false ){ this.footButton( ); } if ( src == this.b_clr ) { this.clearButton ( ); } if ( src == this.b_add && this.operation == false ) { this.operation = true; this.addButton ( ) ; } if ( src == this.b_sub && this.operation == false ) { this.operation = true; this.subButton ( ) ; } if ( src == this.b_mul && this.operation == false ) { this.operation = true; this.mulButton ( ) ; } if ( src == this.b_eq && this.operation == false ) { this.operation = true; this.eqButton ( ) ; } if ( src == this.b_div && this.operation == false ) { this.operation = true; this.divButton ( ) ; } if ( src == this.b_dec ) { this.decButton ( ); } } // **** queries ***** /** * returns the last calculated result formatted for the ft-in-16th */ public String getResult ( ) { if ( ! this.modeDecimal ) { return this.convertDoubleToOutputFormat( this.opBuffer1 ); } else { return this.opBuffer1 + ""; } } // **** commands ***** /** * updates this calculators result using the specified value and operation */ public void performOperation ( double value, int operation ) { // create a temp that holds the previous operation entered before the one // which called this method int op = this.operation1; // store the operation that called this method - we will execute that // operation next go round this.operation1 = operation; if ( op == this.ADD ) { this.opBuffer1 = this.opBuffer1 + value; } else if ( op == this.SUB ) { this.opBuffer1 = this.opBuffer1 - value; } if ( op == this.MUL ) { this.opBuffer1 = this.opBuffer1 * value; } if ( op == this.DIV ) { if ( value != 0.0 ) this.opBuffer1 = this.opBuffer1 / value; else { this.clearButton(); this.display.setText("Div by 0 ERROR"); } } } /** * returns the operator that is in the stack and puts the specified operator * on the stack */ private int opStack ( int op ) { int lastOp = this.operation1; this.operation1 = op; return lastOp; } /** * returns a string formatted to the output of the calculator in * "Foot-inch-sixteenth mode from the specified double. */ public String convertDoubleToOutputFormat ( double in ) { // local variables String out = ""; // a string to hold the formatted output int feet = 0; // storage for the feet int inches = 0; // storage for the inches int numerator = 0; // storage for the sixteenths double temp = 0.0; // temporary storage double round = 0.0; // cast to int - take the part before the decimal feet = (int)in; // subtract the buffer from the feet to get the decimal part temp = (in - feet) * 12.0; // get the inches inches = (int)temp; // get the sixteenths numerator = (int)( (temp - inches) * 16.0); // work on the rounding round = ( ( (temp - inches) * 16.0 ) - numerator); // round up a 16th if ( round > 0.5 ){ numerator++; } //check if it caused the 16th's to roll over if ( numerator == 16 ){ numerator = 0; inches++; } // check if it caused the inches to roll over if ( inches == 12 ){ inches = 0; feet++; } // build the string out = this.addFoot( "" + feet ); out = this.addInch( out, ("" + inches ) ); if ( numerator != 0 ) { out = this.addSixteenth( out, ( numerator + "" ) ); } // return the string return out; } /** * returns a double from the specified string ( this calculators display ) */ private double cvtDisplay ( String in ) { if ( this.modeDecimal ){ Double d = new Double ( in ); return d.doubleValue(); } else return convertStringToFloat ( in ); } /** * returns the double equivalent from the specified input string. Input string * shall be formatted to the output of the calculator ft-in-16th */ public double convertStringToFloat ( String in ){ int ftIndex = in.indexOf( '\'' ); int dashIndex = in.indexOf( '-' ); int spaceIndex = in.indexOf( ' ' ); int slashIndex = in.indexOf( '/' ); int inchIndex = in.indexOf( '\"' ); int feet = 0; int inches = 0; int sixteenths = 0; int numerator = 0; int denominator = 0; // if foot mark exists - then we must break the string into parts // the foot mark exists if ( -1 != ftIndex ){ String s = in.substring( 0, ftIndex ); Integer f = new Integer ( in.substring( 0, ftIndex ) ); feet = f.intValue(); } // save the inches - if there are inches, both the dash and inch mark exist // first check if there are no sixteenths if ( -1 != inchIndex && -1 != dashIndex && ( 2 >= ( ( inchIndex - 1 ) - ( dashIndex ) ) ) ) { // an int between the dash and inch marks - could be 1 or two chars Integer f = new Integer ( in.substring( dashIndex + 1, inchIndex ) ); inches = f.intValue(); } // save both the inches and sixteenths else if ( -1 != inchIndex && -1 != dashIndex ) { // an int between the dash and inch marks - could be 1 or two chars Integer f = new Integer ( in.substring( dashIndex + 1, spaceIndex ) ); inches = f.intValue( ); f = new Integer ( in.substring( spaceIndex + 1 ,slashIndex ) ); numerator = f.intValue(); f = new Integer ( in.substring( slashIndex+1, inchIndex )); denominator = f.intValue(); } // the foot mark does not exist so just add feet else { Double d = new Double ( in ); double d1 = d.doubleValue(); feet = (int)d1; } float fraction = 0; if ( denominator != 0 ){ fraction = ((float)numerator / (float)denominator); } float out = feet + ( ( inches + ( fraction ) ) / 12 ); return out; } // **** Private methods **** /** * reset the flags */ private void resetFlags ( ) { // set all of the flags to false this.ft_pressed = false; this.inch_pressed = false; this.sixTeenth_pressed = false; this.maxPressed = false; this.initState = true; this.decPressed = false; this.operation = false; this.b_10.setEnabled( false ); this.b_11.setEnabled( false ); this.b_12.setEnabled( false ); this.b_13.setEnabled( false ); this.b_14.setEnabled( false ); this.b_15.setEnabled( false ); } // borrowed from Sams "Teach yourself Java" // sets all of the constraints of the components // the first two arguments are: cell coordinates, gridx & gridy // the second two: gridwidth & gridheight (number of cells component spans) // the third two: weightx & weighty ( proportions of the rows and columns) private void buildConstraints ( GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy){ gbc.gridx = gx; gbc.gridy = gy; gbc.gridwidth = gw; gbc.gridheight = gh; gbc.weightx = wx; gbc.weighty = wy; } /** * add Foot takes a input string and adds the foot symbol and dash for * the proper output */ private String addFoot ( String ft ) { return ft + "'-"; } /** * Concatenate the inch to the display in the proper ft-in-16th format */ private String addInch ( String ft, String inch ) { return ft + inch + "\""; } /** * Concatenate the sixteenth on to the end of the display in the proper format */ private String addSixteenth ( String in, String sixteenth ) { int len = in.length(); in = in.substring( 0, len - 1 ); // reduce 2/16, 6/16, 10/16, 14/16 if ( sixteenth.equals( "2" ) || sixteenth.equals ( "6" ) || sixteenth.equals( "10" ) || sixteenth.equals ( "14" ) ){ int value = Integer.parseInt( sixteenth ); value = value / 2; return in + " " + value + "/8\""; } // reduce 4/16, 12/16 else if ( sixteenth.equals( "4" ) || sixteenth.equals( "12" ) ) { int value = Integer.parseInt( sixteenth ); value = value / 4; return in + " " + value + "/4\""; } // reduce 1/2 else if ( sixteenth.equals( "8" ) ) { int value = Integer.parseInt( sixteenth ); value = value / 8; return in + " " + value + "/2\""; } // the remaining are all sixteenths and need no reducing else return in + " " + sixteenth + "/16\""; } /** * allow the 10 and eleven buttons to become active */ private void enableFeet ( ){ this.b_10.setEnabled( true ); this.b_11.setEnabled( true ); } /** * allow the 12, 13, 14, 15 buttons to become active */ private void enableSixteenths ( ){ this.b_12.setEnabled( true ); this.b_13.setEnabled( true ); this.b_14.setEnabled( true ); this.b_15.setEnabled( true ); } // constants private final String initOutput = "0"; public final int INITIAL = 0; public final int ADD = 1; public final int SUB = 2; public final int MUL = 3; public final int DIV = 4; // instance variables private double opBuffer1 = 0.0; // the current total in the buffer private int operation1 = this.INITIAL; // the last entered operation private boolean operation = false; // an operation button was just pressed private boolean ft_pressed = false; // the foot button has been pressed private boolean inch_pressed = false; // the inch button has been pressed private boolean sixTeenth_pressed = false; // the sixteenth key has been pressed private boolean modeDecimal = false; // the calculators mode is in decimal private boolean maxPressed = false; // the max number of keys has been pressed // for ft-in-16th only private boolean initState = true; // the calculator is in the initial state private boolean decPressed = false; // the decimal button has been pressed // do we need - I think NOT Panel ptext = new Panel(); Panel pbutton = new Panel(); // the calculators display private TextField display; // this calculators buttons private Button b_0; private Button b_1; private Button b_2; private Button b_3; private Button b_4; private Button b_5; private Button b_6; private Button b_7; private Button b_8; private Button b_9; private Button b_10; private Button b_11; private Button b_12; private Button b_13; private Button b_14; private Button b_15; private Button b_ft; private Button b_clr; private Button b_add; private Button b_sub; private Button b_div; private Button b_eq; private Button b_dec; private Button b_mul; // this calculators checkboxes private Checkbox dec_but; private Checkbox ft_in_but ; } // end of class