Calculator Interactions

 

The calculator example have two methods that are used to handle Interactions from the user. Below we provide a method that does not require any array of string as an argument.

                                      

Method 1

 void EventGo(string spec) {
    Views.Form f = new Views.Form (spec);
     double euro=1;
    double GBP=1;
 for (string c = f.GetControl(); c!=null; c = f.GetControl()) {
  switch (c) {
   case "clear":
    euro=1; GBP=1;
     f.PutText("eurobox",euro.ToString("f"));
      f.PutText("GBPbox",GBP.ToString("f"));

        break;
          case "equals":
        euro=double.Parse(f.GetText("eurobox"));
     GBP =double.Parse(f.GetText("GBPbox"));
    f.PutText("ratebox",(euro/GBP).ToString("f"));
   break;
  default: break;
}
}
f.CloseGUI();
}

 

From the previous page, XML specification from sample1 is parsed to this method (Method 1). All the highlighted parts resembles some sort of interactions. And below we discuss each of this highlighted items.

1. Views.Form f = new Views.Form(spec)

 Create a new window f according to the XML specification spec, wich in our example creates a window in sample1 from the previous page.

2. c = f.GetControl()

This will return a name of the button that has been pressed from the Form or Window f and assign it to the variable c. From the calculator example this can be clear or equals button.

3. f.PutText("eurobox",euro.ToString("f")) or f.PutText("GBPbox",GBP.ToString("f"))

 

This methods takes the value that euro or GBP has and display it on the TextBox called eurobox and GBPbox respectively. From the example this is where we display 1 and 1 on the two text boxes that we have.

 

4. euro=double.Parse(f.GetText("eurobox"));

This takes the value that is on the TextBox called eurobox and assign that value to the double variable euro.

5. f.CloseGui()

Terminates the Gui.

 

The second method from the calculator example is given below. This method is used with the Gui discussed in sample 2 in the previous page. Note that there is no much difference between this method an method 1 when it come to interactions handling, except that this method deals with only one button and the views.Form constructor accepts XML specification and the array of String.

 

Method 2

void GuiGo(string spec,string[] language) {
  Views.Form f = new Views.Form (spec, language);
    double euro, GBP;
     for (string c = f.GetControl(); c!=null; c = f.GetControl()) {
    euro=double.Parse(f.GetText("eurobox"));
   GBP =double.Parse(f.GetText("GBPbox"));
 f.PutText("ratebox",(euro/GBP).ToString("f"));
}
 f.CloseGUI();
}

 

 

<<PREVIOUS  |  NEXT>>