Examples of J box creation

 

Example 1: Creating a simple modal dialog box

The complete J code to create a simple J box is as follows:

 

// create a vertical box

JBox box=createJBox("simpleBoxIdent", "Simple dialog box",

JLayoutVertical, false);

String value;

int width=300;

int height=100;

 

// open a horizontal layout section

box.beginLayoutSection (JLayoutHorizontal,

true, "A beautiful frame");

 

// add a label

box.addLabel("This is a commentary "+NL+"Multi-line");

box.addToggle("tog1", "A toggle", false);

box.addToggle("tog2", "A second toggle", true);

 

// close the previous horizontal layout section.

box.endLayoutSection();

 

box.addField("field1", "Text:", "My text",

             JControlTextField, width);

 

box.addText("text1", "Multi-line text: ",

            "Enter the description:"+NL+"line 1"+NL+"line 2",

            width, height);

// creation of a help button which accesses the file set as a parameter

box.addHelp("Help", getObjingPath()+"/help/whatsnew_us.htm");

 

if (box.show()==true)

{

  StdOut.write("Ok, Results :"+NL);

  box.getValue("field1", value);

  StdOut.write(value+NL);

  box.getValue("text1", value);

  StdOut.write(value+NL); 

  box.getValue("tog1", value);

  StdOut.write(value+NL);

}

else

{

  StdOut.write("Cancel"+NL);

}

 

// Do not forget to delete the box

box.delete();

 

 

The result of this code (shown in Figure 17) can be tested in your test project, by running the related command from the context menu.

 

Figure 17. The newly created simple dialog box

 

 

Example 2: Creating a non-modal dialog box

The complete J code to create a non‑modal dialog box is as follows:

 

Note:      Please note that the three callbacks ("okCallback", "cancelCallback" and "btnCallback") that feature in the J code for the creation of a non-modal dialog box are themselves J methods defined in the "JNoModalBox" metaclass reference.  Their associated J code can be visualized through the "JCode" notes available on each of the J methods in question.

 

JNoModalBox box=createJNoModalBox(

"inscriptionID",

"Inscription",

JLayoutHorizontal,

"default#external#Code#testJBox",

"okCallback()", "cancelCallback()");

 

String content;

String name="Toto";

real real1=2;

 

// add a textField

box.addField("inscriptionIDName", "Name", "",

JControlTextField, 100);

 

// assign the textField value

box.setValue("inscriptionIDName", name);

 

// add a password

box.addField("inscriptionIDPass", "Password", content,

JControlPassword, 100);

 

box.addField("inscriptionIDAge", "Age", real1.toString(),

JControlNumberField,  100);

 

// add a button related to a callback (btnCallback)

box.addButtonBitmap("button2",

 getObjingPath()+"mybmp.bmp", "default#external#Code#testJBox", "btnCallback()");

box.changeColumn(10);

box.addToggle("inscriptionIDMale", "Man", true);

box.addHelp("Help", getObjingPath()+"/help/whatsnew_us.htm");

 

// show the box and set consultation mode

box.show(true);

 

The result of this code (shown in Figure 18) can be tested in your test project, by running the related command from the context menu.

 

Figure 18. The newly created non-modal dialog box

 

 

Callbacks used

The following code is the code for the "okCallback" callback:

String Name;

String Password;

String Age;

 

String Man;

StdOut.write ("ok !", NL);

 

if (getIdent()=="inscriptionID")

{ 

getValue("inscriptionIDName", Name);  getValue("inscriptionIDPass", Password);  getValue("inscriptionIDAge", Age);  getValue("inscriptionIDMale", Man); 

 

if (Man=="true")    

{    

StdOut.write("Mr "); 

 

} 

else 

{     

StdOut.write("Ms "); 

} 

StdOut.write(Name, "You are", Age, "years old and your password is: ", Password,NL);

}

 

// Do not forget to delete the box

delete();

 

 

The following code is the code for the "cancelCallback" callback:

StdOut.write ("Canceled!", NL);

 

// Do not forget to delete the box

delete();

 

 

The following code is the code for the "btnCallback" callback:

String Name;

String Password;

String Age;

String Man;

 

// create a consultation box (with only an OK button)

 

JBox box=createJBox("boxInfo", "Infos",

 JLayoutVertical, true);

 

getValue("inscriptionIDName",Name);

getValue("inscriptionIDPass",Password);

getValue("inscriptionIDAge",Age);

getValue("inscriptionIDMale", Man);

 

if (Man=="true")  box.addLabel("Man");

 

else 

 

box.addLabel("Woman");

box.addLabel("Name:"+Name);

box.addLabel("Password: "+Password);

box.addLabel("Age: "+Age);box.show();

 

// Do not forget to delete the box

box.delete();