GPanTest

De GENIUS
Aller à la navigation Aller à la recherche

GPanTest is just an help to build a GUI where to test locally a widget class. And when we say testing, it is not only to have a static view of the widget but also testing all its functionalities like conditional display or even mathematical computation if any !

In fact, rather than to create a GFrame, then adding buttons to call for read, write, clear, and so on, it is easier to call directly the GPanTest] class as explained below.

Let us take the example given for conditional display ...

public class myPanel extends GPanel {
 
  GButton but1;
  GButton but2;
  GButton but3;
  GCheckBox cb;
 
  public myPanel() {
    but1 = new GButton("Bouton 1");
    but2 = new GButton("Bouton 2");
    but3 = new GButton("Bouton 3");
    cb   = new GCheckBox("Display button 3"); 
  }
 
  public void generic() throws GException {
    put(but1);
    put(but2);
    if ( cb.isSelected() ) { put(but3); } // Easy, isn't it ?
    put(cb);
   }
   
   public void display() throws GException { generic(); }
   
}

We will have just to add the following main method:

  public static void main(String[] args) {
    myPanel test = new myPanel();
    GPanTest panTest = new GPanTest("Test of myPanel", test);
    panTest .display();
  }

By executing this method, the widget will appear inside a Frame. Up to that level, there is not a great improvement thanks to calling directly GFrame!

But, if we add the GReadWrite and/or the GClear interface, the frame will include other buttons allowing to test all these functionalities. You will have also the possibility to specify the name of the file where data will be read or written ...

public class myPanel extends GPanel implements GReadWrite, GClear {

  ...

  public static void main(String[] args) {
    myPanel test = new myPanel();
    GPanTest panTest = new GPanTest("Test of myPanel", test, "myPanel.xml");
    panTest .display();
  }


GPanTest.jpg


Return to the introduction ↑ Go to the next page →