The International Sample Application brings together the power and functionality of JBuilder's Java Beans Component Library and DataExpress architecture into an internationally enabled, multilingual, on-line shopping applet/application.
Some of the techniques demonstrated in this sample:
Note: This sample displays messages in English and several different European and Asian languages. You will only be able to see messages in the languages for which you have the appropriate font installed and for which you have the corresponding entry in your JDK font.properties file. sample.font.properties includes the correct settings for several languages supported by the JDK. After modifying it appropriately for your locale, you will need to copy it to the \JBuilder\java\lib directory under the proper name for your operating system locale. For more detailed information, refer to the "Adding Fonts to the Java Runtime" section under the "JDK Guide to New Features/Internationalization" section of JBuilder's JDK Documentation.
This sample has been designed to run either as an applet or an application, and to obtain its data from either a DataExpress TextDataFile or the supplied InterBase database. For simplicity, by default it runs as an application and obtains its data from text files installed under your JBuilder samples directory. If you run this sample from the command-line, you must launch it from within the borland/samples/intl directory in order for the text data files to be located.
To run the sample, select Run | Run "IntlDemo" from the main JBuilder menu. To use the InterBase database as the data source, you must first install InterBase and set up an ODBC alias pointing to \JBuilder\samples\borland\samples\intl\application\data\IntlDemo.gdb (or the correct path for your JBuilder installation) using your operating system's ODBC configuration utility. Refer to the "Installing Local InterBase Server" section of the JBuilder Programmer's Guide for detailed instructions on how to do this. Next, you must pass JDBC connection information to the sample via command-line parameters ( Run | Parameters... | Run/Debug | Command line parameters). For example, to use the JDBC-ODBC driver to connect to InterBase, use the following command-line parameters:
jdbc:odbc:IntlDemo SYSDBA masterkey sun.jdbc.odbc.JdbcOdbcDriver
where 'IntlDemo' is the name of the ODBC alias you created which points to the IntlDemo.gdb database.
Before you can run this sample as an applet, you must install InterBase and
create an ODBC alias pointing to the IntlDemo.gdb database. The following
applet parameters defined in the APPLET tag within this .html file are used to make a connection to a database
source.
Applet Parameter Name | Meaning | Default Value |
url | URL to JDBC data source | jdbc:odbc:IntlDemo |
user | user name for logging into database | SYSDBA |
password | password for user name | masterkey |
driver | name of JDBC driver used to connect to database | sun.jdbc.odbc.JdbcOdbcDriver |
To start the applet, select this file in the project's navigation pane, and select 'Run | Run Applet in "IntlDemo.html" from the main menu. Note that because the use of an ODBC driver requires the loading of a .DLL file installed on the client, you will not be able to run this sample as an applet via a browser (such as the JDK1.1 appletviewer) unless you use a 100% pure java JDBC driver (such as Borland's DataGateway or InterBase's InterServer/InterClient) to connect with your web/database server. The basic steps are as follows:
Look in the documentation included with your JDBC driver
for more detailed steps and information.
Things to See and Do While Visiting The Borland Multilingual Store
The application can be viewed abstractly as being composed of three major parts--the data module, user interface, and locale manager. The data module defines the data structures and logic used in the application. It essentially consists of a Database component and several QueryDataSet components added to it and customized via the UI Designer. It also exposes public methods used by the GUI to manage the state of the application. For example, pressing the 'Add To Order' button of the ProductFrame calls the AddProductToOrderLineItem() method of the data module, which adds a row with information about the currently selected row of productsDataSet to orderLineItemDataSet. The GridControl connected to orderLineItemDataSet is automatically notified of the change and updates its display automatically. Similarly, other methods of the data module, typically triggered by events occurring on its DataSets, cause other changes to the application's state. For example, inside the data module, a ColumnChangeListener is attached to the Quantity column of orderLineItemDataSet. When the value in the Quantity column changes, the data module's quantityColumn_changed() method is triggered, which updates the row's extended price and the order's summary totals. To get an overview of the data module, design AppDataModule.java in the UI Designer and examine the properties and events set in the Inspector for each DataSet's Column components.
The frames which comprise the user interface of the sample were also created using the UI Designer. To allow the frames to be used for several different languages, they were all designed using dynamically sizable layout managers such as BorderLayout, GridLayout, or GridBagLayout in order to accomodate variable length text. Also, the Resource Strings wizard was used to automatically extract hard-coded strings from visual components and place them into resource bundles which can be loaded dynamically at runtime based upon the user's current locale.
Finally, each component of the application was designed to be locale-sensitive and resourceable. Each component registers itself with the LocaleChangeManager, which listens to the LocaleChooser bean for locale changes. The LocaleChangeManager broadcasts a 'localeChanged' event to each of its registered listeners, which then update themselves accordingly to the new locale. For example, each frame updates its visual components with strings obtained from the resource bundle for the new locale and redraws itself. The data module similarly updates any visual data within its DataSets which needs to be localized.
The application opens by displaying the WelcomeFrame, which is composed of several Java Beans dropped into and customized in the UI Designer. The LocaleChooser, WrappingTextViewer, and InternationalClock beans each have their own bean info classes which display localized property descriptions in the UI Designer's pop-up property hints. LocaleChooser also demonstrates the use of a custom property editor (actually the LocaleChooser itself) to customize its properties. One very useful technique when debugging bean property editors in the UI Designer is to set the 'jbuilder.logOutput' flag in the \JBuilder\lib\jbuilder.properties file. One can then write output from within a custom property editor to a log file or the console.
Pressing the 'Browse Products' button on the WelcomeFrame brings up the ProductFrame, from which the store's products can be browsed. The frame uses the WrappingTextViewer's data-aware ability to display product descriptions from the productsDataSet in the data module. The ViewOnlyNavigationBar is also a data-aware bean, which was connected via the UI Designer to the productsDataSet. Pressing the navigation buttons calls navigation methods on the productsDataSet. Because the WrappingTextViewer bean is also attached to productsDataSet, it automatically navigates in unison with the navigation bar.
The 'View Order' button of the ProductFrame displays
the main order entry form, OrderFrame. It contains several sample
beans which take advantage of special features of JBuilder's Model-View
component architecture to implement interesting behavior. These beans
can be dropped from the component palette and customized via the UI Designer.
The AnnotatedEmptyItemPainter bean, for example, is a custom 'item painter'
which, when asked to paint, displays the word "<required>" if it doesn't
have a value. In the order line item area, the ResourceableItemPainter
bean is used as the item painter for the 'description' column. It
takes a product id, looks up the id in a resource bundle, and displays
the corresponding localized value. Finally, the IntegerSpinItemEditor
is an example of a custom 'item editor' used to control entry into the
'quantity' column. It is composed of a MaskableTextItemEditor to
restrict entries to digits and a ScrollBar to increase and decrease the
entry value. Because its edit mask can be set dynamically, the MaskableTextItemEditor
is also used as the item editor for the credit card no column. When
a credit card is selected, its edit mask is set to the appropriate digit
entry pattern.
Package Name | Description |
borland.samples.intl | main project file and application launcher |
borland.samples.intl.application | data module and supporting files; application exception handler |
borland.samples.intl.application.data | TextDataFiles and InterBase database used by the sample |
borland.samples.intl.application.resources | localized application resources |
borland.samples.intl.beans | JavaBeans used in the application |
borland.samples.intl.beans.event | event and event listener interface used by locale-sensitive beans |
borland.samples.intl.beans.resources | resources (images and resourcing bundles) used by the beans |
borland.samples.intl.gui | classes used to build the application's GUI |
borland.samples.intl.gui.resources | resources (images and ResourceBundles) used by GUI elements |