BEEJ Examples

1. Minimal Usage (

Minimal has just a "print" button, which causes the expression to be printed to the console, and an ExpressionEditor. The ExpressionEditor is initialized with a MinimalExpressionPanel. A MinimalExpressionPanel has just a checkbox. All instances of ExpressionEditor must be initialized with a certain type of ExpressionPanel. You, the programmer, must provide this by extending BEEJ's ExpressionPanel. To do so, begin with as a model. You should do everything it does (except for the checkbox, obviously).

2. Practical Usage (

FullText provides an ExpressionEditor with a more complex ExpressionPanel, FullTextExpressionPanel. This example is based on the idea of a user constructing a SQL query's WHERE clause (but they can use a simple GUI) for an articles database. Some useful features shown in this example are "listening" to the ExpressionEditor (notice how the code box is automatically updated whenever the ExpressionEditor changes) and inserting the ExpressionEditor in a ScrollPane. A ScrollPane is a very good idea, since a user may "add" and "split" expressions as much as they want, causing the ExpressionEditor to be possibly very large.

The FullTextExpressionPanel shows a combo box (representing a SQL field) and a text box for the user to type in a word or phrase. You have full control over the functionality of your ExpressionPanel; GUI options do not have to directly correspond to SQL (or any boolean expression language) statements. For example, in the FullTextExpressionPanel, they "anything" option in the combo box actually represents all 3 preceding options. If this is selected, the toString() method of the ExpressionPanel actually returns a more complex expression that encompasses all 3 options.