Fruit basket program in wxJavaScript using Mozilla SpiderMonkey

  • From: Jamal Mazrui <empower@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Sat, 15 Nov 2008 16:08:37 -0500 (EST)

From the archive
http://EmpowermentZone.com/wxjs_fruit.zip

This fruit basket program is written in JavaScript, one of the most widely
used programming languages due to its presence on the web.  The program is
run with an interpreter called wxJavaScript, available at
http://www.wxjavascript.net

This interpreter is based on the SpiderMonkey JavaScript engine developed
by the Mozilla Foundation at
https://developer.mozilla.org/en/SpiderMonkey

wxJavaScript is compiled with Visual C++ 2008 Express.  The executable
depends on C++ runtime files.  If you do not already have them installed,
you can download the Visual C++ 2008 Redistributable Package from
http://www.microsoft.com/downloads/details.aspx?familyid=9B2DA534-3E03-4391-8A4D-074B9F2BC1BF&displaylang=en

The interpreter includes a module that wraps the wxWidgets GUI library
developed at
http://wxWidgets.org

Other modules are also part of the package, including MySQL and SQLite.

This archive includes a batch file, run.bat, for running the fruit basket
program with the interpreter.  The source code, wxjs_fruit.js, is also
pasted below.  The interpreter can also be run in an interactive mode for
testing expressions in JavaScript.  Text tutorials on this language are
included in the archive
http://EmpowermentZone.com/html_doc.zip

Jamal

/*
Fruit basket program in JavaScript
Public domain by Jamal Mazrui
*/

// Create the dialog window
dlg = new wxDialog(null, -1, "Fruit Basket", wxDefaultPosition, new
wxSize(513, 176));

// Create the label and edit box for inputting a fruit name, e.g., apple
lblFruit = new wxStaticText(dlg, -1, "&Fruit:", new  wxPoint(14, 14),
wxDefaultSize);
txtFruit = new wxTextCtrl(dlg, -1, "", new wxPoint(43, 14),
wxDefaultSize);

// Create the label and listbox serving as a basket for fruit
lblBasket = new wxStaticText(dlg, -1, "&Basket:", new wxPoint(251, 14),
wxDefaultSize);
lstBasket = new wxListBox(dlg, -1, new wxPoint(293,14), wxDefaultSize,
{});

// Create the default, Add button and its event handler
btnAdd = new wxButton(dlg, -1, "&Add", new wxPoint(190, 121),
wxDefaultSize);
btnAdd.setDefault();
btnAdd.onClicked = function() {
sValue = txtFruit.value;
if (sValue == "") return wxMessageBox("No fruit to add!", "Alert",
wxICON_EXCLAMATION, dlg);

lstBasket.append(sValue);
txtFruit.clear();
iCount = lstBasket.count;
iIndex = iCount - 1;
lstBasket.selection = iIndex;
}

// Create the Delete button and its event handler
btnDelete = new wxButton(dlg, -1, "&Delete", new wxPoint(217, 121),
wxDefaultSize);
btnDelete.onClicked = function() {
iIndex = lstBasket.selection;
if (iIndex == -1) return wxMessageBox("No fruit to delete!", "Alert",
wxICON_EXCLAMATION, dlg);

lstBasket.deleteItem(iIndex);
iCount = lstBasket.count;
if(iIndex == iCount) iIndex--;
lstBasket.selection = iIndex;
}

// Create the event handler that confirms whether to close the program
when Alt+F4 is pressed
dlg.onClose = function (event) {
if (wxMessageBox("Exit program?", "Confirm", wxYES_NO, dlg) == wxYES)
dlg.destroy();
}

// Show the dialog
dlg.centre();
dlg.show(true);

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts:

  • » Fruit basket program in wxJavaScript using Mozilla SpiderMonkey - Jamal Mazrui