/**  PanelSizer      Modification of the simple ReadInteger
 *                   but where the size of the iopanel is 
 *                   optionally picked up from the commanp line
 *
 */

import uk.ac.ed.ph.sciprog.*;                  // Import Display classes


public class PanelSizer{                       // Define main class
    public static void main(String args[]){     // main program start

    //                 Setup the Display 

	Display panel = null;           //    Declare a null Display
	                                //    MUST be declared outside if{}

	String title = "A simple input/output program";

	if(args.length < 2) {                // Size not given
	    panel = new Display(title);      // Default Display call
	}
	else {                               // Argumnents available

	    //          Parse the two integers from args[0] and args[1]
	    //          both of which are Strings
	    //          Note trim() methods removes ``stray'' spaces
	    //          which can upset the parse method

	    int xPanel = Integer.parseInt(args[0].trim());
	    int yPanel = Integer.parseInt(args[1].trim());
	    panel = new Display(title,xPanel,yPanel); // Alternate call.
	}

	//        Rest of program is just ReadInteger from basic-io


	Input number = new Input("Give an integer", 10);     // Construct input
	panel.addInput(number);                              // Add to display

    //                  Loop ``for ever'' reading + writing   
    //                  See next section on loops for details.
    while( true ){

	 //             Print message, wait until ready, then read integer
	panel.println("Change integer and then press GO button");
	panel.waitForButtonPress();

	int iValue = number.getInt();                   // Read the integer
	
	//            Print out the integer to the output part of the Display

	panel.println("Value of integer is : " + iValue);
    }                            
  }
}
