Introjb
Introjb
Borland ®
™
VERSION 7 JBuilder
Borland Software Corporation
100 Enterprise Way, Scotts Valley, CA 95066-3249
www.borland.com
Refer to the file DEPLOY.TXT located in the redist directory of your JBuilder product for a complete list of files that
you can distribute in accordance with the JBuilder License Statement and Limited Warranty.
Borland Software Corporation may have patents and/or pending patent applications covering subject matter in this
document. Please refer to the product CD or the About dialog box for the list of applicable patents. The furnishing of
this document does not give you any license to these patents.
COPYRIGHT © 1997–2002 Borland Software Corporation. All rights reserved. All Borland brand and product names
are trademarks or registered trademarks of Borland Software Corporation in the United States and other countries.
All other marks are the property of their respective owners.
For third-party conditions and disclaimers, see the Release Notes on your JBuilder product CD.
Printed in the U.S.A.
JBE0070WW21000introjb 2E1R0402
0203040506-9 8 7 6 5 4 3 2 1
PDF
Contents
Chapter 1 Navigating and searching in the
AppBrowser . . . . . . . . . . . . . . . . . 4-16
Introduction 1-1 Navigation shortcuts . . . . . . . . . . . 4-16
Documentation conventions . . . . . . . . . . . 1-2
Searching trees . . . . . . . . . . . . . . . 4-16
Note to Macintosh users . . . . . . . . . . . . 1-4
Finding classes . . . . . . . . . . . . . . . 4-17
Contacting Borland developer support . . . . . 1-5
Using Favorites . . . . . . . . . . . . . . 4-18
Online resources . . . . . . . . . . . . . . . . 1-5
Working in the editor . . . . . . . . . . . . . . . 4-18
World Wide Web . . . . . . . . . . . . . . . . 1-5
Editor keymapping . . . . . . . . . . . . . . 4-19
Borland newsgroups . . . . . . . . . . . . . . 1-6
Customizing keymaps . . . . . . . . . . 4-20
Usenet newsgroups . . . . . . . . . . . . . . 1-6
Using the editor's context menu . . . . . . . 4-21
Reporting bugs . . . . . . . . . . . . . . . . . 1-6
Splitting the source view . . . . . . . . . . . 4-21
Chapter 2 Finding text in the editor . . . . . . . . . . . 4-22
Finding a symbol's definition . . . . . . . . 4-22
Learning more about JBuilder 2-1 Finding references to a symbol . . . . . . . 4-23
The JBuilder documentation set . . . . . . . . . 2-1 Javadoc shortcuts in the editor. . . . . . . . 4-23
Additional resources. . . . . . . . . . . . . . . . 2-2 Using @todo tags in the editor . . . . . . 4-25
Printing support in the editor . . . . . . . . 4-25
Chapter 3 Coding shortcuts . . . . . . . . . . . . . . . . . 4-26
Learning more about Java 3-1 CodeInsight . . . . . . . . . . . . . . . . . . 4-26
Online glossaries . . . . . . . . . . . . . . . . . . 3-1 MemberInsight . . . . . . . . . . . . . . . 4-28
Books . . . . . . . . . . . . . . . . . . . . . . . . 3-1 ClassInsight. . . . . . . . . . . . . . . . . 4-28
Using JBuilder's online help . . . . . . . . . . . 3-3 ParameterInsight. . . . . . . . . . . . . . 4-29
How to get Help . . . . . . . . . . . . . . . . 3-3 Find Definition (Drill Down) . . . . . . . 4-30
Tool tip expression evaluation . . . . . . 4-30
Chapter 4 ExpressionInsight . . . . . . . . . . . . . 4-30
The JBuilder environment 4-1 Configuring CodeInsight . . . . . . . . . 4-30
Working in the AppBrowser . . . . . . . . . . . 4-2 Code templates . . . . . . . . . . . . . . . . 4-30
Main menu . . . . . . . . . . . . . . . . . . . 4-3 Editing code templates . . . . . . . . . . 4-31
Toolbar. . . . . . . . . . . . . . . . . . . . . . 4-3 Customizing the editor . . . . . . . . . . . . . . 4-32
Project pane . . . . . . . . . . . . . . . . . . . 4-5 Customizing editor behavior. . . . . . . . . 4-33
Setting project properties . . . . . . . . . 4-7 Editor options . . . . . . . . . . . . . . . 4-34
Default project properties . . . . . . . . . 4-8 Display options . . . . . . . . . . . . . . . . 4-36
Structure pane . . . . . . . . . . . . . . . . . 4-8 Color options . . . . . . . . . . . . . . . . . 4-37
Viewing Javadoc information . . . . . . . 4-8 CodeInsight options. . . . . . . . . . . . . . 4-38
Sorting in the structure pane . . . . . . . 4-8 MemberInsight options . . . . . . . . . . 4-39
Navigating in the source code . . . . . . . 4-9 ParameterInsight options . . . . . . . . . 4-40
Viewing error messages . . . . . . . . . . 4-10 Display Options button . . . . . . . . . . 4-40
Content pane . . . . . . . . . . . . . . . . . . 4-11 Templates options . . . . . . . . . . . . . . . 4-43
File tabs . . . . . . . . . . . . . . . . . . . 4-11 Java structure options. . . . . . . . . . . . . 4-44
File view tabs . . . . . . . . . . . . . . . . 4-11 Customizing JBuilder's IDE . . . . . . . . . . . 4-45
Resizing the content pane . . . . . . . . . 4-13 Browser options . . . . . . . . . . . . . . . . 4-46
Message pane . . . . . . . . . . . . . . . . . . 4-13 File Types options . . . . . . . . . . . . . . . 4-48
Debugger . . . . . . . . . . . . . . . . . . . . 4-14 Web options . . . . . . . . . . . . . . . . . . 4-49
Status bars. . . . . . . . . . . . . . . . . . . . 4-15 XML options . . . . . . . . . . . . . . . . . . 4-50
i
Run/Debug options . . . . . . . . . . . . . . 4-51 Editing libraries . . . . . . . . . . . . . . . . . 7-4
Audio options. . . . . . . . . . . . . . . . . . 4-51 Display of library lists . . . . . . . . . . . . . 7-5
UML options . . . . . . . . . . . . . . . . . . 4-53 Setting project properties. . . . . . . . . . . . . . 7-5
EJB Designer options. . . . . . . . . . . . . . 4-55 Setting the JDK . . . . . . . . . . . . . . . . . 7-6
Editing the JDK . . . . . . . . . . . . . . . . . 7-7
Chapter 5 Debugging with -classic. . . . . . . . . . . 7-7
Automating code development 5-1 Setting the JDK in SE and Enterprise . . . 7-8
Working with the visual design tools . . . . . . 5-1 Configuring JDKs . . . . . . . . . . . . . . . 7-10
Using the object gallery . . . . . . . . . . . . . . 5-3 Setting paths for required libraries . . . . . 7-10
Using wizards to get a quick start . . . . . . . . 5-3 Packages . . . . . . . . . . . . . . . . . . . . . . 7-11
.java file location = source path +
Chapter 6 package path . . . . . . . . . . . . . . . . . 7-12
Creating and managing projects 6-1 .class file location = output path +
Creating a new project. . . . . . . . . . . . . . . 6-2 package path . . . . . . . . . . . . . . . . . 7-13
Creating a new project with the Using packages in JBuilder. . . . . . . . . . 7-13
Project wizard . . . . . . . . . . . . . . . . . 6-2 Package naming guidelines . . . . . . . . . 7-14
Step 1: Selecting project name and How JBuilder constructs paths . . . . . . . . . 7-14
template . . . . . . . . . . . . . . . . . . 6-2 Source path. . . . . . . . . . . . . . . . . . . 7-15
Step 2: Setting project paths . . . . . . . . 6-4 Output path . . . . . . . . . . . . . . . . . . 7-15
Step 3: Setting general project Class path . . . . . . . . . . . . . . . . . . . 7-16
settings . . . . . . . . . . . . . . . . . . . 6-6 Browse path . . . . . . . . . . . . . . . . . . 7-16
Creating a project from existing files . . . . . . 6-8 Doc path . . . . . . . . . . . . . . . . . . . . 7-17
Step 1: Selecting source directory and Backup path . . . . . . . . . . . . . . . . . . 7-17
name for your new JBuilder project . . . . 6-9 Working directory . . . . . . . . . . . . . . . 7-17
Displaying files. . . . . . . . . . . . . . . . . . . 6-10 Where are my files? . . . . . . . . . . . . . . . . 7-17
Switching between files . . . . . . . . . . . . 6-10 How JBuilder finds files when you
Saving projects . . . . . . . . . . . . . . . . . . . 6-11 drill down . . . . . . . . . . . . . . . . . . 7-18
Saving and closing projects . . . . . . . . . . 6-11 How JBuilder finds files when you
Opening an existing project. . . . . . . . . . . . 6-12 compile . . . . . . . . . . . . . . . . . . . . 7-18
Creating a new Java source file . . . . . . . . . . 6-13 How JBuilder finds class files when
Managing projects . . . . . . . . . . . . . . . . . 6-14 you run or debug . . . . . . . . . . . . . . 7-18
Adding to a project . . . . . . . . . . . . . . . 6-14
Adding folders . . . . . . . . . . . . . . . 6-14
Chapter 8
Adding files and packages. . . . . . . . . 6-15 Comparing files and versions 8-1
Removing material from a project . . . . . . 6-15 Version handling glossary . . . . . . . . . . . . . 8-1
Deleting material . . . . . . . . . . . . . . . . 6-16 Comparing two files . . . . . . . . . . . . . . . . 8-2
Opening a file outside of a project . . . . . . 6-16 Using the history view . . . . . . . . . . . . . . . 8-4
Renaming projects and files . . . . . . . . . . 6-16 Contents page . . . . . . . . . . . . . . . . . . 8-5
Working with multiple projects . . . . . . . . . 6-17 Diff page . . . . . . . . . . . . . . . . . . . . . 8-6
Switching between projects . . . . . . . . . . 6-17 Info page . . . . . . . . . . . . . . . . . . . . . 8-7
Saving multiple projects . . . . . . . . . . . . 6-18
Chapter 9
Chapter 7 Tutorial: Building an application 9-1
Managing paths 7-1 Step 1: Creating the project . . . . . . . . . . . . 9-2
Working with libraries. . . . . . . . . . . . . . . 7-1 Step 2: Generating your source files . . . . . . . 9-5
What is a library? . . . . . . . . . . . . . . . . 7-1 Step 3: Compiling and running your
Adding and configuring libraries . . . . . . 7-2 application . . . . . . . . . . . . . . . . . . . . . 9-8
ii
Step 4: Customizing your application's Step 4: Customizing your applet's user
user interface . . . . . . . . . . . . . . . . . . . 9-8 interface . . . . . . . . . . . . . . . . . . . . 10-13
Step 5: Adding a component to your Step 5: Adding AWT components to
application . . . . . . . . . . . . . . . . . . . . 9-11 your applet. . . . . . . . . . . . . . . . . . . 10-18
Step 6: Editing your source code . . . . . . . . . 9-12 Step 6: Editing your source code . . . . . . . 10-21
Step 7: Compiling and running your Step 7: Deploying your applet . . . . . . . . . 10-25
application . . . . . . . . . . . . . . . . . . . . 9-13 Deploying your applet with the jar tool . 10-26
Step 8: Running your application from the Deploying your applet with the
command line . . . . . . . . . . . . . . . . . . 9-14 Archive Builder . . . . . . . . . . . . . . 10-27
Step 9: Adding an event to a button . . . . . . . 9-15 Step 8: Modifying the HTML file . . . . . . . 10-30
Step 10: Completing your UI . . . . . . . . . . . 9-18 Step 9: Running your deployed applet
Step 11: Preparing your application for from the command line. . . . . . . . . . . . 10-32
deployment . . . . . . . . . . . . . . . . . . . . 9-19 Testing your deployed applet on the Web . . 10-33
Step 12: Running your deployed Applet source code . . . . . . . . . . . . . . . 10-34
application from the Applet HTML source code for
command line . . . . . . . . . . . . . . . . . . 9-22 GoodEveningApplet.html . . . . . . . . 10-34
HelloWorld source code. . . . . . . . . . . . . . 9-23 Applet class source code for
Source code for HelloWorldFrame.java . . . 9-23 GoodEveningApplet.java. . . . . . . . . 10-35
Source code for HelloWorldClass.java . . . . 9-26
Source code for Chapter 11
HelloWorldFrame_AboutBox.java . . . . . 9-27 Tutorial: Using the history view 11-1
Step 1: Generating multiple versions of
Chapter 10 a file. . . . . . . . . . . . . . . . . . . . . . . . 11-2
Tutorial: Building an applet 10-1 Step 2: Using the Contents page. . . . . . . . . 11-4
Overview . . . . . . . . . . . . . . . . . . . . . . 10-2 Step 3: Using the Diff page. . . . . . . . . . . . 11-6
Step 1: Creating the project . . . . . . . . . . . . 10-3 Step 4: Using the Info page . . . . . . . . . . . 11-7
Step 2: Generating your source files . . . . . . . 10-7
Step 3: Compiling and running your Index I-1
applet . . . . . . . . . . . . . . . . . . . . . . 10-11
iii
Tables
1.1 Typeface and symbol conventions . . . . . 1-3 4.4 Commands for finding text . . . . . . . . 4-22
1.2 Platform conventions and directories . . . 1-4 4.5 Page header variables . . . . . . . . . . . 4-25
4.1 Toolbar buttons . . . . . . . . . . . . . . . 4-3 4.6 CodeInsight shortcut keystrokes . . . . . 4-27
4.2 File view tabs. . . . . . . . . . . . . . . . . 4-12 7.1 Colors in library lists . . . . . . . . . . . . . 7-5
4.3 Navigation keyboard shortcuts . . . . . . 4-16
Figures
4.1 The AppBrowser window . . . . . . . . . 4-2 4.5 CodeInsight pop-up window . . . . . . . 4-27
4.2 Project pane context menu . . . . . . . . . 4-6 5.1 JBuilder in design view . . . . . . . . . . . 5-2
4.3 Structure View Properties. . . . . . . . . . 4-9 9.1 AppBrowser elements . . . . . . . . . . . . 9-7
4.4 Default (CUA) Keymap Editor . . . . . . . 4-20 9.2 UI designer elements . . . . . . . . . . . . . 9-9
iv
Chapter
1
Introduction
Chapter1
Introduction 1-1
Documentation conventions
Documentation conventions
The Borland documentation for JBuilder uses the typefaces and symbols
described in the table below to indicate special text.
Introduction 1-3
Documentation conventions
Online resources
You can get information from any of these online sources:
Introduction 1-5
Contacting Borland developer support
Borland newsgroups
You can register JBuilder and participate in many threaded discussion
groups devoted to JBuilder.
You can find user-supported newsgroups for JBuilder and other Borland
products at http://www.borland.com/newsgroups/
Usenet newsgroups
The following Usenet groups are devoted to Java and related
programming issues:
• news:comp.lang.java.advocacy
• news:comp.lang.java.announce
• news:comp.lang.java.beans
• news:comp.lang.java.databases
• news:comp.lang.java.gui
• news:comp.lang.java.help
• news:comp.lang.java.machine
• news:comp.lang.java.programmer
• news:comp.lang.java.security
• news:comp.lang.java.softwaretools
Note These newsgroups are maintained by users and are not official Borland
sites.
Reporting bugs
If you find what you think may be a bug in the software, please report it in
the Support Programs page at http://www.borland.com/devsupport/
namerica/. Click the “Reporting Defects” link to bring up the Entry Form.
When you report a bug, please include all the steps needed to reproduce
the bug, including any special environmental settings you used and other
programs you were using with JBuilder. Please be specific about the
expected behavior versus what actually happened.
If you have comments (compliments, suggestions, or issues) with the
JBuilder documentation, you may email [email protected]. This is for
documentation issues only. Please note that you must address support
issues to developer support.
JBuilder is made by developers for developers. We really value your
input, because it helps us to improve our product.
Additional resources
For additional information about JBuilder and Java:
• Visit the JBuilder web site at http://www.borland.com/jbuilder/ and
the Borland Community web site at http://community.borland.com/
• For books on JBuilder, visit
http://www.borland.com/jbuilder/books/.
• For a list of Java books and glossaries, see Chapter 3, “Learning more
about Java.”
Online glossaries
These are Sun Microsystem's online Java glossaries:
• Sun Microsystem's Java Glossary in HTML:
http://java.sun.com/docs/glossary.nonjava.html#top
• Sun Microsystem's Java Glossary in Java:
http://java.sun.com/docs/glossary.html
Books
Books that tell you more about Java programming are listed below. The
first half of the list is in ascending order of difficulty. The second half
covers special topics such as network programming and JavaBeans.
1. Philosophical in tone. Good for understanding concepts: not good for “how-to”.
• You can view class reference information from the AppBrowser in two
more ways:
• Double-click a class name in the structure pane, then select the Doc
tab.
• Right-click a class name in the source pane, choose Find Definition,
then select the Doc tab.
• From the Inspector, choose a property or event and press F1.
See also
• “Using JBuilder's online help” in the “Learning more about JBuilder”
chapter of the online Introducing JBuilder.
Main menu
The Team menu is a The main menu is at the top of the AppBrowser. For an explanation of
feature of JBuilder SE each menu, see “JBuilder menus” in the JBuilder environment chapter of
and Enterprise the online help (Help/JBuilder Environment).
Toolbar
The main toolbar is displayed at the top of the AppBrowser under the
menu bar. It is composed of smaller toolbars grouped by functionality:
File, Edit, Search, Build, Run/Debug, Navigate, and Help. You can
modify the toolbar display by checking or unchecking selections on the
View|Toolbars menu.
Available features vary For details on exactly which features are available from a toolbar icon in
slightly by JBuilder your edition of JBuilder, see “JBuilder menus” in the JBuilder
edition. environment chapter of the online help (Help/JBuilder Environment)
The toolbar provides shortcut buttons for the following menu commands:
Project pane
To develop programs in the JBuilder environment, you must first create a
project. A JBuilder project organizes the files you use and maintains the
properties you set. JBuilder stores project settings in a project file, an XML
type of file with a .jpx extension. The project file is automatically modified
by project changes, not accessed directly by the user. The active project file
is the top node in the project pane.
The project pane displays the contents of the active project. It consists of
the following items:
• A small toolbar with four buttons:
• Close Project: closes active project.
• Add Files/Packages: opens the Add Files Or Packages To Project
dialog box.
• Remove From Project: removes selected files from the project.
• Refresh: refreshes project and automatic search for source packages
(Project|Project Properties|General).
• A drop-down list of all opened projects.
• A tree view of the contents of the active project.
• A context-sensitive menu for each node (file, package, or directory) in
the project pane, accessed by right-clicking the node.
To create an entirely new project, choose File|New Project from the main
menu, or choose File|New, choose the Project icon on the Project page of
the object gallery, and select the Project icon. To create a new project using
existing files, choose the Project For Existing Code icon from this same
page.
If you have existing files or classes you want to add to your project, click
the Add Files/Packages button on the project pane toolbar and browse to
select a file or package. To create a new JAVA source file, choose File|
New Class to open the Class wizard; the class you create is placed in the
current project. If you use the Application wizard, on the General page of
the object gallery, the new application is added to the current project. To
add an empty file to your project, select the Add Files/Packages button
and enter a name and extension in the File Name field of the Add Files Or
Packages To Project dialog box.
You can freely navigate the project tree, click and multi-select files, or
right-click and select items from the context menu, without ever opening a
file. The context menu selections vary by the file type selected.
Double-click or select files and press Enter to open files and display them in
the AppBrowser content pane.
Figure 4.2 Project pane context menu
You can open as many projects in the project pane as you wish. Only one
project is active at any given time. The active project appears as the
selected item in the project pane drop-down list.
See also
• Chapter 6, “Creating and managing projects” for more information on
projects.
• “Filtering packages” in Building Applications with JBuilder to understand
how package filtering works.
• “Searching trees” on page 4-16 to learn more about searching in the
project tree.
Important In order to work with a project most effectively, understand how JBuilder
uses paths and libraries. Check the list of references below for more
information.
See also
• “Working with libraries” on page 7-1
• “How JBuilder constructs paths” on page 7-14
• “Where are my files?” on page 7-17
• “Setting project properties” on page 7-5
Structure pane
The structure pane displays the structure of the file currently selected in
the content pane. This structure is displayed in the form of a tree showing
all the members and fields in the file. When appropriate, the structure
pane displays an Errors folder containing any syntax errors and an Imports
folder containing a list of imported packages.
You can quickly search for an element in a file by moving the focus to the
tree in the structure pane and starting to type the name of the element you
want. For more information, see “Searching trees” on page 4-16.
See also
• “Using @todo tags in the editor” on page 4-25
• “Conflicts in Javadoc comments” in Building Applications with JBuilder
These options are also available on the Java Structure page of the Editor
Options dialog box (Tools|Editor Options). For a complete description of
the available options, see “Java structure options” on page 4-44.
When you select an item in the structure pane, the content pane scrolls to
the line that defines the item and highlights the line.
You can also use the structure pane for drilling down into ancestor classes
and interfaces. To see the .java file for an ancestor class, an interface, or
the type of a variable shown in the structure pane, double-click it (or select
it and press Enter). JBuilder shows the file in the structure and content
panes. To search a package, select Search|Find Classes or double-click the
package in the structure pane and select a class in the dialog box to open it
in the content pane. To return to your project, click the Home button on
the main toolbar.
See also
• “About error and warning messages” in Building Applications with
JBuilder.
Content pane
The content pane displays all opened files in a project as a set of tabs. To
open a file in the content pane, double-click it in the project pane, or select
it and press Enter. The name of each opened file is displayed on a tab at the
top of the file in the content pane. When you click a tab, that file becomes
the current file.
The content pane also provides access to various file views and operations
by way of the file view tabs shown at the bottom of each file window.
File tabs
File tabs contain the names of the open files in a selected project in the
content pane. Only the file tabs of open files in the active project are
visible. One file at a time is active in each open editor.
Each file tab has a button which serves two purposes:
• Allows you to close the file with one click on the button.
• Indicates whether the file has changed since it was last saved. If so, it
looks like this: and you will be prompted to save the file before
closing it.
You can customize the tab labels several ways: orientation, label type, and
insertions. Select Tools|IDE Options|Browser to set these options.
See also
• “Browser options” on page 4-46.
Source, Design, Bean, UML, Doc, and History. The tabs available vary by
JBuilder edition.
See also
• View menu for other pane configurations.
Message pane
A tabbed message pane appears at the bottom of the AppBrowser for
displaying hierarchical user messages from different processes, such as:
• Building and compiling
• Running
• Debugging
• Searching
• Refactoring code
• Unit testing
• Version control
JBuilder generates a new tab at the bottom of the message pane for each
new process. These tabs allow you to interact with the running process.
An icon on the tab indicates that a process is active and console input and
output are possible through the message pane text area.
Some processes provide toolbar buttons on the tab that let you stop or
restart the current process. The restart button associated with a process
reuses the settings in effect when the tab was initially created, ignoring
any subsequent changes you may have made. Using this feature, you can
set up several different configurations to be repeatedly tested.
You can run two or more processes simultaneously on the same project or
different projects. A separate project tab is created for each new process
started with the main toolbar Run and Debug buttons.
To start a new run or debug process, make sure the project you want to
run or debug is the active project in the project pane or the file you want to
debug is the current file in the content pane. Then use the buttons on the
main toolbar to start the process.
A Build tab displays during compile if there are errors or warnings.
During some processes, such as running, debugging, version control, and
refactoring, the message pane contains a status bar to advise you of the
progress or result of the current process.
To show or hide the message pane, choose View|Messages or the
Messages button on the toolbar to toggle its state. You can also hide the
message pane by right-clicking the message tabs and choosing Hide
Message View, or pressing Ctrl+Alt+M if you are using the CUA
keymappings. Press the Close Tab button to close a tab in the message
pane. Close individual tabs or all tabs in the message pane by
right-clicking the message tabs and selecting Remove <name> Tab or
Remove All Tabs.
You can also copy from the message pane. Right-click the message pane
and select Copy All or select the text you want to copy and select Copy
Selected Content.
Debugger
Debugging is the process of locating and fixing errors in your programs.
The message pane houses the UI for the debugger.
The debugger includes:
• Vertical tabs which represent the debugger views. The views are
displayed for the currently selected debugging session.
• Horizontal tabs which represent debugging sessions. Each tab
represents a new session.
• The debugger toolbar which is displayed for the currently selected
debugging session.
See also
• “Debugging Java Programs” in Building Applications with JBuilder.
Status bars
There are three status bars in the AppBrowser.
• Main status bar
• File status bar
• Message status bar
The main status bar is displayed at the bottom of the AppBrowser
window and keeps you updated on any processes and their results.
The file status bar is displayed at the bottom of each opened file window
in the content pane. It displays information specific to the current file,
such as the name of the file, the cursor location (line number and column),
and the insertion mode in a text file or the size of an image file.
The message status bar is displayed at the bottom of the message pane
during such processes as running, debugging, and version control.
Searching trees
To search in the project pane, structure pane, and message pane, move
focus to the pane and start typing. A tool tip box is displayed in which you
can define a search filter. By default, the first matching entry is selected.
The next and previous entries are selected with the Up and Down arrow keys.
Press Esc to cancel the search mode. Collapsed nodes of the tree are not
searched.
To search collapsed nodes, use the dot character (.) or Control + dot (Ctrl+.)
keys preceded by the node name. The node is expanded and the search is
limited to the children. For example, as shown below, entering
texteditframe.jb in the structure pane selects the first jButton component in
the TextEditFrame branch.
Normally, entries beginning with the specified text are selected. Use
wildcard characters to expand the search:
• An asterisk matches any string of characters.
• A question mark matches any single character.
Finding classes
Type Ctrl+Minus to invoke the Find Classes dialog. In JBuilder Personal, this
invokes the familiar class browser. In JBuilder SE and Enterprise, it has
two tabs: Search and Browse.
On the Search page,
1 Type into the Search For field and JBuilder populates the Matching List
field.
2 Select the class you want to open.
3 Click OK or press Enter.
The dialog closes and the class opens and becomes the active file in the
editor.
The Browse page lists the packages and source files used by the active
project. Expand a package either by using the expand icon next to it or by
typing the fully qualified name of the class you want to open. The relevant
branch of the tree expands as you type:
Using Favorites
File selection dialog boxes, such as the Add Files Or Packages To Project
dialog box, have quick links to favorite directories. The location of the
Favorites list depends on your OS. For instance, in Windows, they're in a
pane on the left of the dialog box; in Mac, they're on a navigation bar.
Select a Favorite to put the dialog box selection in that directory.
The default links are determined at the code level in JBuilder. However,
you can add and customize new favorites.
To add a favorite link from an open file selection dialog box,
1 Navigate to the directory you want to add.
2 Press the Favorites icon in the upper right corner of the dialog box.
3 Select Add To Favorites.
The Add To Favorites dialog box opens.
4 Type in a name for the link.
5 Click OK or press Enter.
The new favorite is added to the list of favorites. The favorites you add
are distinguished from default favorites by the heart icon.
When necessary, the Favorites list becomes scrollable.
To organize the favorites that you have added, using an open file selection
dialog box,
1 Press the Favorites icon and select Organize Favorites.
The Organize Favorites dialog box appears.
2 Select a favorite from the list.
3 Rename, remove, or move the favorite up or down in the list.
The sort order here determines the sort order in the favorites list.
4 Click OK or press Enter when done.
See also
• “Quick Tips” (Help|Quick Tips)
• “Customizing the editor” on page 4-32
• “Coding shortcuts” on page 4-26
• “Color options” on page 4-37 for syntax highlighting
• “Keymaps of editor emulations” (Help|Keyboard Mappings) for brace
matching and other shortcuts
• “Printing support in the editor” on page 4-25
Editor keymapping
Keyboard shortcuts make certain tasks much faster and easier to do.
Different editors map different keystrokes to the same action. This makes
switching between editors inconvenient at best, risky at worst.
In consideration of different programmers' different habits and needs,
JBuilder provides a number of editor emulations. Choose the one that
you're most comfortable with. The keymaps are documented within
JBuilder as well as in the help system:
• Brief
• CUA
• Emacs
• Macintosh
• Macintosh CodeWarrior
• Visual Studio
1 To choose a different keymapping scheme, either:
• Select Tools|IDE Options and choose the Browser page, or
• Select Tools|Editor Options and choose the Editor page.
2 Then, click the Keymap field.
3 Select the editor emulation you want from the popup menu.
4 Click OK.
The new emulation is active immediately.
Customizing keymaps
In JBuilder Personal, the Keymap Editor is read-only; keymappings can't
be changed. In JBuilder SE and Enterprise, you can change individual
keymappings. You can also create your own keymap using the OpenTools
API.
To access the Keymap Editor,
1 Either:
• Select Tools|IDE Options and choose the Browser page, or
• Select Tools|Editor Options and choose the Editor page.
2 Then click the Customize button next to the Keymap field.
3 Select the command you want to change, remove, or add a keymapping
to.
4 Click the button that allows you to perform the action you want:
Change, Remove, or Add.
Figure 4.4 Default (CUA) Keymap Editor
See also
• Click the Help button in the Keymap Editor.
See also
• Help|Keyboard Mappings for keyboard shortcuts by editor
The Find dialog box and the Replace dialog box both provide the option to
replace text. Other options include case-sensitive searching, use of
wildcards, and defining the extent of the search/replace task.
The Find In Path and Replace In Path dialogs include case sensitivity and
wildcards as options. Other options include which paths to search, what
filters to use, and whether subdirectories should be included in the search.
See also
• “Finding a symbol's definition” in “Refactoring code symbols” in
Building Applications with JBuilder.
See also
• “Finding references to a symbol” in “Refactoring code symbols” in
Building Applications with JBuilder.
Coding shortcuts
JBuilder features CodeInsight for assisting in code completion and code
templates for quickly inserting frequently used code elements in the
editor.
CodeInsight
CodeInsight provides code completion, parameter lists, and tool tip
expression evaluation inside JAVA files and inside the code segments of
JSP files. JBuilder's CodeInsight displays context-sensitive pop-up
windows within the editor that show the following:
• MemberInsight: accessible data members and methods for the current
context.
• ClassInsight: classes accessible through the current class path.
• ParameterInsight: parameters expected for the method being coded.
• Find Definition (Drill Down): drills down to source code for current
variable, method, or class in the editor.
This is a feature of JBuilder • Tool tip expression evaluation: values for variables display in the
SE and Enterprise. debugger.
This is a feature of JBuilder • ExpressionInsight: the contents of the expression selected in the
SE and Enterprise. debugger.
Invoke the CodeInsight tool, select the symbol you want to insert, and
press Enter.
Important The project must be compiled before imported classes are available to
CodeInsight.
See also
• Help|Keyboard Mappings.
• “Customizing the editor” on page 4-32.
• “Finding a symbol's definition” in Building Applications with JBuilder.
MemberInsight
MemberInsight provides a pop-up list of all appropriate method calls for
any given reference prefix depending on your CodeInsight settings. The
pop-up list appears automatically when you type a dot character (.) in a
valid context. You can also invoke the list manually by typing Ctrl+Space or
Ctrl+H.
You can also enter a class name to see valid method, property, and event
names. The code completion feature can also be used to complete
assignment statements. CodeInsight has automatic code completion, too.
If the remainder of the code statement is unique, CodeInsight
automatically fills in the rest of the code and the member list does not
appear.
The member list is based on the current project's imports. Any deprecated
methods are highlighted using strike-out. The list is filtered based on the
accessibility rules of the Java language.
ClassInsight
In JBuilder Personal, ClassInsight is the familiar class browser. To display
ClassInsight, press Ctrl+Alt+Space or Ctrl+Alt+H in the editor and browse to
the class you want to add. The import statement is added automatically.
This is a feature of In JBuilder SE and Enterprise, ClassInsight invokes the ClassInsight
JBuilder SE and dialog box, which can be used to insert classes into your code. To display
Enterprise the dialog box, press Ctrl+Alt+Space or Ctrl+Alt+H in the editor. It has two tabs:
Search and Browse. The Search page provides a search field and a list of
matches for what you type. The Browse page provides a search field and
the class browser.
Begin entering the name of the class you want to insert in your code in the
Search For field. As you type, JBuilder dynamically searches any classes
on the current class path and displays a list of possible matches, which
changes as you type. Press Enter or use double-click to insert the selected
class and Ctrl+Enter to insert the package. You can also use the arrow keys
to navigate the list. To find classes in any libraries, the libraries must be in
your project. When you add a class using ClassInsight, the import
statement is automatically added as the last import statement in your
code. To reorder and optimize your import statements, use Optimize
Imports in the editor. See “Optimize Imports” in Building Applications with
JBuilder.
Important If you've added a source file or library to your project, you must recompile
the project and press the Refresh button in the project pane before
ClassInsight can recognize the additions. Use Project|Make Project or
Project|Rebuild Project to recompile.
See also
• “Optimize Imports” in Building Applications with JBuilder.
• “Adding and configuring libraries” on page 7-2
• “Class path” on page 7-16
Insertion options
This is a feature of ClassInsight has several insertion options that allow you to control how
JBuilder SE and the class name and import statement are inserted in your code. The
Enterprise. following examples use the BorderLayout class in the java.awt package as an
example.
• Insert Short Class Name With Explicit Import
Inserts the short class name with an import statement that includes the
full package and class name. For example,
• Class name inserted: BorderLayout
• Import statement inserted: import java.awt.BorderLayout;
• Insert Short Class Name With Package Import
Inserts the short class name with the package import statement. For
example,
• Class name inserted: BorderLayout
• Import statement inserted:import java.awt.*;
• Insert Fully Qualified Class Name
Inserts the complete class name (package + class name) without an
import statement. For example,
• Class name inserted: java.awt.BorderLayout
• Import statement inserted: none
See also
• “Optimize Imports” in Building Applications with JBuilder.
ParameterInsight
When you are coding a method call, you can display a list of expected
parameters for the method. To display the parameter list, type a method
ExpressionInsight
This is a feature of Suspend the debugger and place the cursor inside an expression to access
JBuilder SE and ExpressionInsight. ExpressionInsight is a small pop-up window that
Enterprise. displays the contents of the selected expression in a tree structure.
See also
• “Debugging Java programs” in Building Applications with JBuilder.
Configuring CodeInsight
To configure CodeInsight, right-click in the source pane, select Editor
Options, and click the CodeInsight page or choose Tools|Editor Options|
CodeInsight. For more information, see “CodeInsight options” on
page 4-38.
JBuilder provides several pre-defined code templates. Select Tools|Editor
Options|Templates to view the available templates.
Code templates
Adding, editing, and Code templates are snippets of frequently used code elements that you
deleting templates are can insert into your code to save repetitive typing. You can use code
features of JBuilder SE templates in the editor to speed up the coding process.
and Enterprise. Code
templates are read-only
in JBuilder Personal.
Important When you create or modify templates, JBuilder does not format them
according to the preferences. You must set the braces and indents
manually.
For more information, see “Templates options” on page 4-43.
See also
• “Customizing JBuilder's IDE” on page 4-45
• Max Indent
Specifies the maximum indentation depth used by Smart Indent. The
default is 50. Either select or type a different value.
• Backup Level
Specifies the number of file backups. The maximum number of backups
is 30.
Editor options
Available editor options include:
• Smart Key Options
Determines how smart keys work in the editor. Click the expand icon to
expand the list.
• Smart Home: When this option is enabled, Home moves the cursor to
the left of the first non-whitespace character on a line. If the cursor is
already in this position, it is moved to the beginning of the line
instead. The default is off.
• Smart End: When this option is enabled, End moves the cursor to the
right of the last non-whitespace character on a line. If the cursor is
already in this position, it is moved to the end of the line instead. The
default is off.
• Smart Tab: Indents to align the cursor with the left edge of text in the
first non-whitespace line above the current line. Searches for the first
non-whitespace character in the above line that is preceded by
whitespace. If no character matching this description is found, Tab
reverts to indenting to the next block indent position. The default is
off.
• Indent Options
Determines how indents work in the editor. Click the expand icon to
expand the list.
• Smart Indent indents code appropriately, according to how deeply a
given line should be nested. Wrapped text in the middle of a line of
code is indented to line up under the first opening parenthesis of
that line of code, or at the maximum indentation, whichever is less.
• It uses the indentation level set above, in this page of the dialog box.
The cursor can be anywhere in the line of code for the line to be
correctly indented. Default is on.
• Block Indent is an alternative to Smart Indent. When you press Enter,
it positions the cursor under the first non-whitespace character of the
preceding non-whitespace line. When appropriate, it aligns the
closing curly brace with the first column of the opening curly brace's
line of code and automatically indents the next line. The cursor must
be at the beginning of the line for the line to be indented correctly.
• Smart Paste indents pasted-in code appropriately in the new
location. Smart Indent must be on to use this option. Default is on.
• Use Tab Character, when indenting a line, automatically replaces
space characters with tab characters as appropriate. For example, if
Block Indent is set to 2 and Tab Size is set to 8, tabbing four times at
the start of a line will result in a single tab character. Tab characters
are never inserted after non-whitespace characters, even if this
option is enabled. The default is off.
• Display Options
Click the expand icon. Blink Caret makes the cursor blink off and on.
The default is on.
• Save Options
Determines how files are saved. Click the expand icon to expand the list.
• Strip Trailing Whitespaces removes all trailing white spaces from the
file when saving. The default is on.
• Change Leading Tabs To Spaces replaces all leading tab characters
with spaces. The default is off.
• Change Leading Spaces To Tabs replaces leading spaces with tabs.
The default is off.
• Search Options
Determines how searches are handled. Click the expand icon to expand
the list.
• Show Dialog When Search Fails shows a Search Failed dialog when
the search fails. When this option is not selected, the dialog is
suppressed and the message is displayed on the status bar. This
doesn't affect the Find feature in the toolbar.
The default is on.
• Search Word At Cursor automatically places the word closest to the
cursor position in the Text To Find field in the Find/Replace Text
dialog box. The default is off.
• Brace Match Options
Determines how braces are handled. Click the expand icon to expand
the list.
• Generate Closing Curly Brace inserts a closing curly brace for each
unmatched opening curly brace you type. The inserted brace is
indented according to the indent options selected in this dialog box.
Default is on.
Display options
Use the Display page of the Editor Options dialog box to select display
and font options for the content pane. It may take a moment to load
available fonts before it displays. The Sample box displays a sample of the
font currently used in the editor.
The Display page controls:
• Visible Right Margin
Displays a thin, vertical gray line at the right margin of the editor. The
default is on.
• Right Margin
Sets the right margin of the editor. The default is 80 characters. The valid
range is 1 to 1024, with presets available from the popup menu. If Visible
Right Margin is selected, a gray vertical line is displayed at this margin.
• Font Family
Selects a font type from the available screen fonts installed on your
system (shown in the list). The editor displays and uses only
monospaced screen fonts. Sample text is displayed in the Sample box.
Default is DialogInput.
• Font Size
Selects a font size from the pre-defined font sizes associated with the
font you selected in the Editor Font list box. Sample text is displayed in
the Sample box. Default is 12, with a range from 6 to 30.
• Sample
Displays a sample of the font and size that are currently selected to be
used in the editor.
Color options
Use the Color page of the Editor Options dialog box to specify how the
different elements of your code appear in the editor. You can specify
foreground and background colors for anything listed in the Screen
Element list. The editor supports syntax highlighting for Java, HTML, JSP,
C, C++, SQL, XML, XSL, XSD, XSP, DTD, and IDL.
The sample code at the bottom of the dialog box displays a preview of the
selected settings.
CodeInsight options
Use the CodeInsight page of the Editor Options dialog box to configure
CodeInsight. The CodeInsight page is where you:
• Enable automatic pop-up for member or parameter list display.
• Set the duration of the delay before the code completion window or the
parameter list is displayed.
• Set advanced options.
If the Auto Popup options on this page are selected, the pop-up windows
display after you enter the required activation characters (detailed below)
on the keyboard and pause for the delay specified in the Delay slider bar.
If the Auto Popup options on this page are not selected, CodeInsight is
available on demand by pressing shortcut keys. These keystrokes can vary
by editor keymappings. To check or set your editor keymapping, choose
Tools|Editor Options|Editor and choose an editor from the Keymap
drop-down list. Then, choose the Customize button to configure or view
the CodeInsight keystrokes in the Keymap Editor dialog box. The Keymap
Editor is read-only in JBuilder Personal. See Help|Keyboard Mappings
for a complete list of keymappings.
MemberInsight options
These options control how CodeInsight displays MemberInsight, the list
of accessible methods and data members for the current context.
• Auto Complete On Invocation
When you invoke MemberInsight, if there is only one possible match in
the list, it is automatically accepted and entered into the code. The
pop-up list won't appear. You do not have to press Enter to commit the
selection. To turn off this feature, uncheck the Auto Complete On
Invocation checkbox. The default is on.
ParameterInsight options
These options control how CodeInsight displays ParameterInsight, the list
of parameters expected for the current method being coded.
• Include Deprecated Methods
Determines whether deprecated methods are shown in the
ParameterInsight window. The default is on.
• Show Class Context
Displays class name at the top of the pop-up window. The default is on.
MemberInsight page
The MemberInsight page configures how CodeInsight displays the list of
accessible methods and data members for the current context.
• Selected Foreground
The color of the text for the selected entry in the MemberInsight
window.
• Selected Background
The color of the background for the selected entry in the
MemberInsight window.
• Sample
Displays selected settings in a list.
ParameterInsight page
The ParameterInsight page configures how CodeInsight displays the list
of parameters expected for the current method.
ParameterInsight page has the following settings:
• Use Strike-through For Deprecated Methods
Strikes through data methods that have been deprecated. Note that
deprecated methods appear only if the Include Deprecated Methods
checkbox has been selected on the Tools|Editor Options|CodeInsight
page. The default is on.
• Use Custom Font And Colors
Allows you to set custom font and colors for the display. The default is
off.
• Font
The font in which to display the entries in the Parameter List window.
• Size
The text point size.
• Foreground
The color of the text.
• Background
The color of the background.
• Sample
Displays selected settings in a list.
Templates options
Adding, editing, and Use the Editor Options|Templates page to create and edit templates for
deleting templates is a individual code elements you frequently use.
feature of JBuilder SE
and Enterprise. Code
templates are read-only
in JBuilder Personal.
• Templates
The existing code templates. Choose a template to see its expansion in
the Code box at the bottom of the dialog box.
• Code
The code contained in the template.
Use the pipe character (|) to denote the caret position after the template
is expanded. Use '\|' to enter a literal pipe character.
In the following sample code template, the cursor moves between the
parentheses when the template is expanded:
if (|) {
}
else {
}
Adding templates is a • Add
feature of JBuilder SE
and Enterprise. Code
Displays the Add Code Template dialog box where you enter the new
templates are read-only code template name and description.
in JBuilder Personal. When you add a new template, it inserts it in the Templates list in
alphabetical order. Click OK to return to the Templates page. Type the
code for the template in the Code text editing area, then click OK.
Important When you create or modify templates, JBuilder does not format them
according to the preferences. You must set braces and indentations
manually.
Editing templates is a • Edit
feature of JBuilder SE
Displays the Edit Code Template dialog box where you can edit the
and Enterprise. Code
templates are read-only
selected template name and description. To use it,
in JBuilder Personal. a Select a template then click the Edit button to access the Edit Code
Template dialog box.
b Edit the template's name and description.
c Click OK to return to the Templates page.
d Change the code for the template in the Code text editing area of the
Templates page.
e Click OK to close the Editor Options dialog box.
Important When you create or modify templates, JBuilder does not format them
according to the preferences. You must set the braces and indents
manually.
Deleting templates is a • Delete
feature of JBuilder SE
and Enterprise. Code
Deletes the selected template.
templates are read-only
in JBuilder Personal. Java structure options
You can control the organization of your files in the structure pane by
selecting the Java Structure page in the Editor Options dialog box. You can
also right-click in the structure pane and choose Properties.
• Parse Delay
Use the Parse Delay slider to specify how often you want JBuilder to
parse your code and register a change to the structure pane. If you
work on large files, it's recommended that you increase the parse delay.
The default is 750ms.
• Structure order
These menu options are not mutually exclusive, so you can choose any
combination. If no options are selected, the structure elements are listed
in the structure pane in the same order they appear in the source code.
Choose any, all, or none of these options:
• Group By Visibility: Groups the structure elements according to
their visibility. All public elements are listed first, followed by all
protected elements, and then all private elements. The default is on.
Browser options
Use the Browser page of the IDE Options dialog to configure JBuilder's
AppBrowser. To open the Browser page, choose Tools|IDE Options, and
choose the Browser tab.
The Browser page of the IDE Options dialog box controls the following:
• Look And Feel
Sets the look and feel for the JBuilder IDE.
• Keymap
Sets the keymapping definitions for the editor and the IDE menus. For
a complete listing of editor keymapping definitions, see “Keyboard
Mappings” available on the Help menu.
• Customize
Displays the Keymap Editor dialog box where you can customize your
keymapping for the selected keymap. The Keymap Editor is read-only
in JBuilder Personal.
Web options
This is a feature of The Web page of the IDE Options dialog box sets Web options. To display
JBuilder Enterprise. this dialog box, choose Tools|IDE Options and choose the Web tab.
XML options
This is a feature of The XML page of the IDE Options dialog box sets general options and
JBuilder SE and trace options for XML documents. To display this dialog box, choose
Enterprise. Tools|IDE Options and choose the XML tab.
Run/Debug options
Use the Run/Debug page of the IDE Options dialog box to customize the
runtime and debug update intervals. To open the Run/Debug page,
choose Tools|IDE Options, then click the Run/Debug tab.
See also
• “Customizing the debugger” in Building Applications with JBuilder.
Audio options
The Audio page controls JBuilder's audio feedback for various events and
is enabled by default. JBuilder currently provides an audio theme stored
in the JBuilder lib/audio/ directory. You can also add custom audio files
and attach them to specified events. To open the Audio page, choose
Tools|IDE Options, then click the Audio tab.
Customize the audio by setting these options in the IDE Options dialog box:
• Audio Volume
Disables or enables the audio and adjusts the volume.
• Theme
Displays a drop-down list of audio themes. Choose JBuilder's default
audio theme or select a custom theme.
• Audio events
Enables or disables audio for individual events.
• Play
Plays the selected audio event.
To add custom audio files to JBuilder,
1 Create a 16-bit .wav audio file for each event.
2 Name each file according to the event:
• build_errors.wav
• build_successful.wav
• build_warnings.wav
• exception.wav
• find_failed.wav
• find_in_path.wav
• process_stopped.wav
• stopped_at_breakpoint.wav
UML options
This is a feature of Use the UML page of the IDE Options dialog box to globally configure the
JBuilder Enterprise. display of UML diagrams in JBuilder's UML browser. You can control
such options as sorting, font, and font size, as well as color of text, arrows,
and backgrounds. To open the UML page, choose Tools|IDE Options, and
choose the UML tab.
• Font Family
Selects a font type for the EJB Designer to use from the available screen
fonts installed on your system (shown in the list).
• Font Size
Select a font size for the EJB Designer to use from the predefined font
sizes associated with the font you selected in the Font Family list box.
• Screen Element
Choose an EJB element in the Screen Element list and select a new color
to change the default color displayed in the EJB Designer. Select a
standard or a custom color to the right of the Screen Element list.
• Color
Displays the selected standard or custom color. Select a color from the
palette or choose the Select Custom Color button and choose or create a
custom color.
Three designers share the design surface on the Design page of the content
pane: the UI designer, the menu designer, and the column designer.
The UI designer is used in assembling visual UI components that inherit
java.awt.Container. When you first click the Design tab after opening a file
in the content pane, JBuilder displays the UI designer by default. UI
components appear in the UI folder of the component tree.
The menu designer is used to create menus. Menu components appear in
the Menu folder of the component tree.
The column designer is a The column designer allows you to work visually with data set
feature of JBuilder components. Data set components appear in the Data Access folder of the
Enterprise component tree.
See also
• “Designing a user interface” in Designing User Interfaces
• “Managing the component palette” in Designing User Interfaces
• “Designing menus” in Designing User Interfaces
You're asked to configure file associations when starting JBuilder for the
first time. JBuilder prompts you to associate .class, .java, and project file
types of files with JBuilder. Doing so makes JBuilder the default program
for opening and viewing these files. You can change these configurations
by selecting Tools|Configure File Associations to invoke the Configure
File Associations dialog box.
• Click the ellipsis (...) button to use a different project as the template
via the Open Project dialog box.
4 Choose whether to generate an HTML project notes file. The initial
information in this file is generated from the class Javadoc fields set in
Step 3 of the Project wizard.
5 Click Next to go to Step 2.
If the Finish button is enabled, you can click it, accepting JBuilder's
defaults for the rest of the wizard, and create the project immediately.
1 Select the project's JDK, output, backup, and working directory paths.
JBuilder suggests the parent project directory set in Step 1 as the
working directory.
The working directory is the starting directory that JBuilder gives a
program when it is launched. Any directory may be configured as the
working directory.
“The project directory” is another way of saying “the parent directory
of the project file.” The Project and Project For Existing Code wizards
use this as the default root directory for the project tree.
To change any of these paths, either type in the new path or navigate to
it by clicking the ellipsis (...) button next to the appropriate field.
See also
• “Setting the JDK” on page 7-6
The source, documentation, and libraries settings are available from
tabbed panes below the text field settings. Each page has buttons that
allow you to add new paths, edit existing ones, remove paths from the
list, and alter the order of the settings. Altering the order may improve
performance, since JBuilder generally searches paths in the order seen
here.
2 Set default and test source paths on the Source page. It's possible to
choose the same path for both functions.
The default source path is used by wizards that create source files. The
test source path is used when you use JBuilder's unit testing features.
This provides the option of using a different area for testing so you can
easily separate your tests from your other code. This is most useful in
deployment.
Customize source paths using the buttons on the right:
• Click Add to browse to a source path you want to add.
• Click Edit to choose a source path that will replace the selected one.
• Click Remove to remove the selected path.
• Click Move Up or Move Down to change the order of paths in the
list.
Adding additional source paths means the project works with multiple
source roots. Note that imports automatically select all the source
directories as source roots.
Note If JBuilder can't find the specified source path, it will go through the list
of available paths from the top down. Sort your paths to control which
one is searched first in this case.
3 Set documentation paths on the Documentation page.
Use the buttons on the right to customize this information.
4 Set the libraries needed on the Required Libraries page. Libraries are an
excellent way to handle archived information.
Use the buttons on the right to customize this list.
See also
• “Setting paths for required libraries” on page 7-10
• “Working with libraries” on page 7-1
5 Click Next to go to Step 3.
Alternatively, if you're satisfied with the default values for Step 3, click
Finish in Step 2 to create the new project.
It's recommended that only advanced users change the default paths. If
you enter a path that's syntactically flawed, you can't proceed.
See also
• “Specifying a native encoding for the compiler” in the
“Internationalizing programs with JBuilder” chapter of Building
Applications with JBuilder.
• “Internationalization Tools: native2ascii” at http://java.sun.com/
products/jdk/1.3/docs/tooldocs/tools.html#intl
2 Choose the Enable Assert Keyword option if you want assert
recognized as a keyword. JBuilder supports JDK 1.4 assertions.
Previous to JDK 1.4, assert was a keyword reserved for future use. With
JDK 1.4, the assert keyword has been added to the language and is used
See also
• http://java.sun.com/j2se/1.4/docs/guide/lang/assert.html
3 Select Automatic Source Packages options.
This is a feature of a Enable Source Package Discovery And Compilation is enabled by
JBuilder SE and default.
Enterprise.
When it's enabled, several things happen:
• All packages in the project's source path appear in the project
pane (upper left pane) of the IDE.
• Packages that contain Java files are compiled automatically.
• Files generated by this compilation are copied to the project's out
path.
Not all packages are displayed, only a logical subset determined by
how deeply you tell JBuilder to expose packages.
b Select how deeply you want packages exposed.
JBuilder exposes packages to the level you set, unless adding more
levels to a package will not change the length of the package list. For
instance, if you have these three packages,
one.two.three.four
one.two.three.five
one.two.four.six
and set the package level to three, this is what shows in the project
pane:
one.two.three
one.two.four.six
The two packages one.two.three.four and one.two.three.five are both
contained in one.two.three, so JBuilder represents only the parent
package and allows you to expand the package node to access the
packages and files inside.
The package one.two.four.six is exposed to the fourth level because
shortening the representation won't shorten the package list, so you
might as well see what you've got.
See also
“Packages” on page 7-11
4 Specify the class Javadoc fields. These can be used in the project notes
file, your application's Help|About dialog box, and can also be inserted
as Javadoc header comments in wizard-generated files created for your
project.
Select a field to edit and enter the appropriate text in the Text column.
Find References is a 5 Check Include References From Project Library Class Files if you want
feature of JBuilder SE to be able to find references to any of the project libraries. The Find
and Enterprise. UML is a References command on the editor's context menu allows you to
feature of JBuilder discover all source files that use a given symbol. Also check this if you
Enterprise. want your project's UML diagrams to show references from project
libraries.
See also
• “Finding references to a symbol” in “Refactoring with JBuilder” in
Building Applications with JBuilder
• “Visualizing code with UML” in Building Applications with JBuilder
6 Click Finish when done.
JBuilder returns you to the IDE with your new project open.
The settings in Step 2 and Step 3 can be changed on the Paths page and the
General page of the Project Properties dialog box (Project|Project
Properties).
See also
• “Setting paths for required libraries” on page 7-10
• “Using the Run command” in Building Applications with JBuilder
Displaying files
JBuilder displays each open file of a project in the content pane of the
AppBrowser. Double-click a file in the project pane to open it in the
content pane. A tab with the file name appears at the top of the content
pane.
The following figure shows a project file, Welcome.jpx, in the project pane
with the source files listed below it. This project contains a package and
three source files. Two files are open in the content pane with the selected
file, WelcomeApp.java, showing in the source pane.
Right-click the project file to display a menu with such menu selections as
Open, Add Files/Packages, Remove From Project, Close Project, Make,
Rebuild, and Properties. Many of these menu selections are also available
from the Project menu.
See also
• “Working with multiple projects” on page 6-17
• Chapter 4, “The JBuilder environment”
Saving projects
When you are working on a project, you can save it to the suggested
location or to a directory of your choice. By default, JBuilder saves projects
to the jbproject directory of your home directory, although this depends
on how your system is set up. Each project is saved to its own directory
within jbproject. Each project directory includes a project file, an optional
.html file for project notes, a classes subdirectory for generated files (such
as .class files), a src subdirectory for source files, and a bak subdirectory
for backup files.
See also
• “How JBuilder constructs paths” on page 7-14
• “Where are my files?” on page 7-17
See also
• “Adding to a project” on page 6-14
• “Packages” on page 7-11
• “Step 3: Setting general project settings” on page 6-6
After you edit a file, save it by choosing File|Save or clicking the Save File
icon. The path and parent directory of the file appears at the top of the
AppBrowser window when the file is selected and open.
Managing projects
JBuilder is designed to support the developer in performing as many
development tasks as possible. JBuilder's project tools, rich IDE, and
extensive editor features automate and simplify the work of development
while allowing you to focus on your code.
See also
• Chapter 4, “The JBuilder environment”
Adding to a project
In the AppBrowser, you can add folders, new files, and existing files to
your project. Many of these commands are available from the project
pane's context-sensitive (right-click) menu as well as the main menu.
For larger projects, you can use project folders to organize your project's
hierarchy.
Note Project folders are for organizational purposes only and do not
correspond to directories on disk.
Adding folders
Project folders don't affect the directory tree. They are organizing tools
that allow you to sort elements of a project in a way that's useful to you
without affecting the directory structure.
To add a project folder to a project,
1 Select the project in the project pane (upper left).
2 Choose File|New Folder from the main menu or right-click in the
project pane.
3 Select New Folder.
Tip To nest the new folder inside an existing one, select the existing folder
before choosing File|New Folder.
4 Type the name of the folder.
5 Click OK or press Enter.
To add a file to a folder,
1 Either right-click the folder and choose Add Files/Packages to open the
Add Files Or Packages To Project dialog box, or select the folder and
click the Add Files/Packages button on the project pane toolbar.
2 Navigate on the Explorer page of the Add Files To Project dialog box to
the directory that contains the file you want to add.
3 Select the file and click Open.
Deleting material
You can also delete unwanted files, classes, and packages from the disk by
right-clicking the item in the project pane and choosing Delete.
Caution This permanently deletes the files from the project and the computer's
hard disk.
Caution Renaming projects and files does not change the package and file names
referenced inside the code. JBuilder SE and Enterprise provide rename
refactoring. This changes all of the uses of the old name to match the new
name.
See also
• “Refactoring code symbols” in Building Applications with JBuilder
Managing paths
Chapter7
7
Paths are the infrastructure of Java program development. Paths provide a
program with what it needs to run. When you set a JDK, you tell the
program what path to use to access a JDK. When you create a library, you
collate a set of paths that the program will need. Every time a file
references another file, it uses a path to get to it.
This section covers how JBuilder constructs paths, how to manipulate
paths in the Project Properties dialog box, and how to use path-based tools
such as libraries and CodeInsight features.
See also
• “How JBuilder constructs paths” on page 7-14
Library configurations are saved in .library files and can be saved to
several locations:
• User Home
Saves the .library file to the <.jbuilder> directory in the user's home
directory.
• JBuilder
This is a feature of Saves the .library file to the <jbuilder>/lib directory. Multiple users
JBuilder SE and who are using JBuilder on a network or sharing JBuilder on a single
Enterprise machine have access to the libraries in this folder.
• Project
This is a feature of Saves the .library file in the current project's directory. When using the
JBuilder SE and version control features, the .library file is checked in with the other
Enterprise project files.
• User-defined folder
This is a feature of Saves the .library file to a user-defined folder or shared directory. You
JBuilder Enterprise must add the new folder in the Configure Libraries dialog box before it
can appear in the drop-down list.
2 Click the New button under the left pane to open the New Library wizard.
See also
• “Setting paths for required libraries” on page 7-10
• “Using JAR Files: The Basics” at http://java.sun.com/docs/books/
tutorial/jar/basics/index.html
• “New Library wizard”
• “How JBuilder constructs paths” on page 7-14
• “Where are my files?” on page 7-17
Editing libraries
To edit an existing library,
1 Select Tools|Configure Libraries.
2 Select the library you want to edit from the list of libraries.
3 Select the Class, Source, or Documentation tab to choose the library
path you want to edit.
4 Select the library path and click Edit.
5 Browse to a file or user-defined folder in the Select Directory dialog
box. Click OK.
6 Click Add to browse to a library to add.
7 Select a library path and click Remove to remove it.
8 Reorder library paths by selecting a library path and clicking Move Up
or Move Down.
Tip JBuilder searches libraries in the order listed.
9 Click OK or press Enter to close the Configure Libraries dialog box.
This is a feature of • UML page: set options to change the display of UML diagrams, such as
JBuilder Enterprise exclude package/class filters and diagram references from generated
source.
add, edit, and remove JDKs in the Configure JDKs dialog box. See “Setting
the JDK” on page 7-6.
For JBuilder Personal, you can edit the JDK in the Configure JDKs dialog
box (Tools|Configure JDKs). See “Editing the JDK” on page 7-7.
2 Click the Change button to the right of the JDK Home Path field. The
Select Directory dialog box appears.
3 Browse to the target JDK.
4 Click OK to change the JDK.
Note the revised JDK name and home path in the Configure JDKs
dialog box.
5 Click OK to close the Configure JDKs dialog box.
If it's not listed, select New to open the New JDK wizard.
a Click the ellipsis button and browse to the home directory of the JDK
you want to add to the list. Click OK. Note that the JDK Name field
is filled in automatically.
b Select the location to store the JDK specifications:
• User Home: saves the JDK specifications in a .library file in the
.jbuilder directory of the user's home directory. Save to this
location if you want the JDK available to all projects.
This is a feature of • JBuilder: saves the JDK specifications in a .library file in the
JBuilder SE and jbuilder directory. Multiple users who are using JBuilder on a
Enterprise. network or sharing JBuilder on a single machine have access to
the JDKs in this folder.
This is a feature of • Project: saves the JDK specifications in a .library file in the
JBuilder SE and current project's directory. Save to this location if you only want
Enterprise. the JDK available to this project.
This is a feature of • User-defined folder: saves the JDK specifications to an existing
JBuilder Enterprise. user-defined folder or shared directory. You must add the new
folder (select Tools|Configure JDK and click Add Folder) before
it can appear in the drop-down list.
c Click OK. Note that the JDK specification has been added to the
specified directory in the Select A JDK dialog box.
4 Click OK to close the Select A JDK dialog box. Note that the JDK path is
updated to the new selection.
5 Click OK to close the Project Properties dialog box.
6 Save the project. The JDK version is updated in the project file.
Tip You can add, edit, and delete JDKs by selecting Tools|Configure JDKs.
You can also modify the Default Project Properties (Project|Default
Project Properties) to change the JDK for all future projects.
Configuring JDKs
Adding and deleting JDKs are features of JBuilder SE and Enterprise.
You can add, edit, and delete JDKs in the Configure JDKs dialog box
(Tools|Configure JDKs). JBuilder Personal users can edit JDKs as
explained in “Editing the JDK” on page 7-7.
In this dialog box, you can:
• Name the JDK by selecting the Rename button.
• Add, edit, remove, and reorder JDK class, source, and documentation
files.
• Open the New JDK wizard and add JDKs by selecting the New button.
This is a feature of • Add a folder that others can share.
JBuilder Enterprise.
• Delete an existing JDK from the list.
See also
• Configure JDKs dialog box Help button.
• New JDK wizard Help button.
You can select libraries in the Required Libraries list on the Paths page
and edit, delete, or change their order in the library list.
Note Libraries are searched in the order listed. To switch the order of libraries,
select a library, then click Move Up or Move Down.
The Add button displays the Select One Or More Libraries dialog box,
where you choose the libraries to add to your project. Select New in this
dialog box to open the New Library wizard and create a new library.
See also
• “Working with libraries” on page 7-1
Packages
Java groups .java and .class files in a package. All the files that make up
the source for a Java package are in one subdirectory (src) and all
compiled files are in another subdirectory (classes). When building
applications, JBuilder uses the name of the project as the default name for
the package in the Application or Applet wizard. For instance, if the
project name is untitled1.jpx, the Application or Applet wizard suggests
using a package name of untitled1. Suggested package names are always
based on the project name.
Let's look at a sample project to see how the package name affects the file
structure.
Note In these examples, paths reflect the UNIX platform. See “Documentation
conventions” on page 1-2 for information on how paths are documented
here.
To organize your project, you might have your project in a folder called
SampleProject. This project folder contains a project file (africa.jpx), a
classes directory and a src directory:
In creating this project, you'll want to create your own packages to hold
related sources and classes. In this example, africa.jpx contains a package
name of feline.africa. This package contains source files on certain felines
found in Africa: Lions, Cheetahs and Leopards.
The class files, which are saved in a directory structure that matches the
package name, are saved in the classes subdirectory within the project.
The src subdirectory, which contains the .java files, has the same structure
as the class subdirectory.
Continuing with the SampleProject example, the source path for Lion.java
is:
/<home>/<username>/jbproject/SampleProject/src
Note For the definition of the <home> directory, see “Documentation
conventions” on page 1-2.
The second part of the directory path is determined by the package name,
which in this case is feline.africa.
Note Java nomenclature uses a period (.) to separate the levels of a package.
The .java file location for Lion.java is:
/<home>/<username>/jbproject/SampleProject/src/feline/africa/Lion.java
See also
• “How JBuilder constructs paths” on page 7-14
See also
• “How JBuilder constructs paths” on page 7-14
See also
• Filtering packages in Building Applications with JBuilder.
• Browse path
• Doc path
• Backup path
• Working directory
Paths are set at a project level. To set paths, use the Project Properties
dialog box. See “Setting project properties” on page 7-5 for more
information.
In the construction of paths, JBuilder eliminates duplicate path names.
This prevents potential problems with DOS limitations in Windows.
Note In these examples, paths reflect the UNIX platform. See “Documentation
conventions” on page 1-2.
Source path
The source path controls where the compiler looks for source files. The
source path is constructed from both of the following:
• The path defined on the Source tab of the Paths page of the Project
Properties dialog box.
• The directory for generated files. This directory contains source files
that are automatically generated by the IDE. Examples of these source
files include IDL server and skeleton files. The directory for generated
files is placed in the Output path. You can change this option on the
Build page of the Project Properties dialog box.
The complete source path is composed of these two elements in this order:
source path + output path/generated source
Using the SampleProject as an example, the source path for the
feline.africa.jpx project is:
/<home>/<username>/jbproject/SampleProject/src
Output path
The output path contains the .class files created by JBuilder. The output
path is constructed from the path defined in the output path text box,
located on the Paths page of the Project Properties dialog box.
Files are placed in a directory whose path matches the output path + the
package name. There is only one output path per project.
For example, in the SampleProject example, the output path for the
feline.africa.jpx project is:
/<home>/<username>/jbproject/SampleProject/classes
Class path
The class path is used during compiling. This path is constructed from all
of the following:
• The Output path
• The class path for each library listed on the Paths page of the Project
Properties dialog box (in the same order in which they are listed)
• The target JDK version selected on the Paths page of the Project
Properties dialog box
The complete class path is composed of these elements in this order:
output path + library class paths (in the order libraries are listed in the
Project Properties dialog box) + target JDK version
For example, the complete class path for Lion.class is:
/<home>/<username>/jbproject/SampleProject/classes:
/user/jbuilder/lib/dbswing3.1.jar:/user/jdk1.3/bin
The class path is displayed on the Build tab after you compile.
Browse path
The browse path is used by the IDE when you:
• Use CodeInsight
• Choose Find Definition from the editor pop-up menu
• Choose Search|Find Classes.
• Run the debugger
The browse path is constructed from all of the following:
• The Source path
• The source path for each library listed on the Paths page of the Project
Properties dialog box (in the same order in which they are listed)
• The source path for the target JDK version selected on the Paths page of
the Project Properties dialog box
The complete browse path is composed of these elements in this order:
source path + library source paths (in the order libraries are listed on the
Paths page of the Project Properties dialog box) + JDK target version
source path
For example, the complete browse path for Lion.class is:
/<home>/<username>/jbproject/SampleProject/src:
/user/jbuilder/lib/dbswing3.1.jar:
/user/jbuilder/lib/dx3.1.jar:/user/jdk1.3/bin
Doc path
The doc path is the path or paths that contain HTML documentation files
for API class files. This allows reference documentation to be displayed in
the Doc page of the content pane.
The doc path can be set on the Paths page of the Project Properties dialog
box. Paths are searched in the order listed.
Backup path
JBuilder uses the backup path to store backup versions of source files. The
default backup directory is:
/<home>/<username>/jbproject/[project name]/bak
Important JSP files, HTML files, and some other text files are not treated as source
files. These files are backed up in their original directories.
However, you can include these backups in the backup directory of your
project instead. To do so,
1 Select Project|Project Properties and look at the Paths page.
2 Select the Source page inside the Paths page.
3 Click Add in the Source page. This brings up the Select One Or More
Directories dialog box.
4 Browse to the project backup directory, select it, and click OK.
Working directory
The working directory is the starting directory that JBuilder gives a
program when it is launched. Any directory may be configured as the
working directory. By default, it has the same name as the project file.
It's generally the parent directory of the source directory. It's the default
parent directory of the output, backup, documentation, and library
directories.
• The class path is used during compiling and at runtime and for certain
Enterprise editor features.
• The browse path is used by the IDE when using CodeInsight, Find
Definition in the editor, searching, and debugging.
• The output path contains the .class files created by JBuilder when you
compile your project.
See also
• “How JBuilder constructs paths” on page 7-14
• “Working with libraries” on page 7-1
Term Definition
revision, version These terms are basically interchangeable in this context. Each
time you change a file (or revise it), you make a new version
(or revision) of that file.
diff Diff is short for difference. A diff is an area of text that is
different between two files or between two versions of the
same file.
diff block An area of difference between two files or two versions of the
same file. These are most easily seen using a diff view, where
the two files or file versions are merged into one apparent
source and differences between them are flagged.
Note that JBuilder's diff handling mechanisms evaluate files
physically, not logically. They compare only the actual text of
the files or the versions against each other, not their logic or
code structure.
revert Make a previous version of the file the current version again.
version control A way of managing revisions that maintains records of all
changes made to every file under version control. Version
control systems generally also include other code
management features such as branching and version labeling.
Term Definition
backup copy A saved version of the file that is maintained in the local
backup directory for that file.
JBuilder uses backup copies as prior file versions. Set the
number of backups you want to keep from the Editor page of
Tools|Editor Options. When the limit is reached, the latest
versions will be kept and renumbered appropriately.
buffer The latest working version you use in JBuilder. It includes
unsaved changes.
repository In version control, where file master versions and revision
histories are kept.
workspace In version control, the local files and directory structure that
you change directly.
2 Select the first file and click OK. The Select New File dialog box
appears.
3 Select the second file and click OK. The Compare Files dialog box
appears:
The Source View displays the two files side by side. Tile the display in
either direction by selecting the appropriate radio button. Synchronize
scrolling between the two panes by checking the Synchronize Scrolling
checkbox.
The Source View supports basic text editing functions. This lets you make
changes to both buffers. If you make changes, Refresh File and Save File
context (right-click) menu options become available:
The Diff View supports individual diff block reversion. The first file you
choose shows as the older version and the second file shows as the newer
version. This means that, where the old and the new file have two
different blocks of text in the same part of the file, JBuilder can make them
the same by replacing the newer file's block of text with the corresponding
block of text in the old file.
If you change files using the Compare Files dialog box, you will be
prompted to save your changes to each file when you close the dialog box.
Icon Description
A backup version of the file.
The version of the file that's in the buffer. The buffer version includes
unsaved changes.
These are features of JBuilder Enterprise:
The version of the file that you checked out from the repository.
Tip With your cursor in a revision list, scroll through the list by pressing Enter
or by using your keyboard arrow keys.
The Contents and Diff pages have a source viewer. The source viewer
displays the source code of the file version selected in the revision list. You
can copy and paste from the source viewer into the editor, though you
cannot edit the source viewer directly. This simplifies retrieving old work
while it protects the integrity of the prior file versions.
Synchronize Scrolling
The Diff page is a feature Synchronize Scrolling synchronizes scrolling between the source viewers
of JBuilder SE and in the Contents or Diff History pages and the editor. It matches the line of
Enterprise. text that contains the cursor with the nearest matching line of text in the
other view. Where there's no matching text in that region of the file, it
matches line numbers. This button is available in the Contents and Diff
pages.
Synchronize Scrolling is also a checkbox option in the File|Compare Files
dialog box.
Contents page
The Contents page of the history view displays all available versions of
the active file. The revision list at the top allows you to sort the file
versions by version type, revision number, label, date of change, or
author. Click on a heading to sort by that heading. Click again to reverse
the sort order. Select a version in the revision list to view its source in the
source viewer:
Diff page
This is a feature of The Diff page displays differences between two selected versions of the
JBuilder SE and active file. The revision lists at the top allow you to sort the file versions by
Enterprise version type, revision number, or date of change. The Refresh Revision
Info and Synchronize Scrolling buttons are enabled on this page.
There are two revision lists in the Diff page. One is titled From and the
other is titled To. Select a version in the From list and select a different
In each block of difference, the diff deletion (with the minus sign) is in red
and the diff addition (with the plus sign) is in yellow. If the buffer is
selected as the To version, undo an addition by clicking the Undo button
in the gutter.
Use the diff arrows to move between diff blocks. You can also use Alt + n to
move to the next diff block, or Alt + p to move to the previous diff block.
Tip Version control users can see all changes made to the repository since the
original checkout. Select the original repository version in the From area
and the file version with the highest revision number from the To area.
JBuilder updates the most recent version with repository changes.
Info page
This is a feature of The Info page of the history view displays the full text of labels and
JBuilder Enterprise comments for any selected version of the active file. The revision list at the
top allows you to sort the file versions by version type, revision number,
label, date of change, author, or comment. The Refresh Revision Info and
Revert To Previous Revision buttons are enabled on this page.
To use the Info page, select a version from the revision list. Its label (if it
has one) and the comments that were entered describing the revision are
displayed in the lower part of the page:
The Info page is a screening tool. It allows you to sift through the
comments of all of the revisions of a file so you can get an overview of the
changes made to that file.
For further information on any of these features, press F1 from within any
of the History pages. This displays context help for the content pane.
Select History from the table in the context help.
When you have completed the tutorial, you will have a Java application
that looks like this:
See also
• “How JBuilder constructs paths” on page 7-14
• “Where are my files?” on page 7-17
9 Double-click HelloWorld.html, the project notes file, to view it in the
content pane located in the center of the AppBrowser. Note that it
contains the project name, author, company, and description
information you just entered in Step 3 of the Project wizard.
2 Select the General tab and double-click the Application icon to open the
Application wizard.
3 Accept the default package name, helloworld, in Step 1 of the
Application wizard.
By default, the wizard takes the package name from the project file
name, HelloWorld.jpx.
4 Enter HelloWorldClass in the Class Name field.
This is a case-sensitive Java class name.
5 Check Generate Header Comments.
When you select this option, the project notes information you entered
in Step 3 of the Project wizard appear at the beginning of each source
file that the Application wizard generates.
11 Choose File|Save All to save the source files and the project file.
Note The source files are saved to: /<home>/jbproject/HelloWorld/src/
helloworld.
The class files generated from the source files by the Java compiler are
saved to: /<home>/jbproject/HelloWorld/classes/helloworld.
Note The running application in this tutorial reflects the Windows Look & Feel.
2 Choose File|Exit in the “Hello World” application to close it.
3 Right-click the HelloWorldClass tab in the message pane at the bottom
of the AppBrowser and choose Remove “HelloWorldClass” Tab to
close any messages.
3 Click the Swing Containers tab on the component palette above the UI
designer and choose the JPanel component to add a panel to your
design.
Tip Place the cursor over a component on the palette to see its name in a
tool tip.
4 Click the center of the frame in the UI designer to drop the component
into the center of your design's frame.
Note The constraints property in the Inspector should be Center. If not, click
the column to the right of the constraints property, and choose Center
from the drop-down list.
2 Drop the component into your design's JPanel using one of the
following two methods:
• Click jPanel1 in the component tree. This places it in the upper-left
corner of the panel.
• Click jPanel1 in the UI designer. The upper-left corner of the
component is placed where you click.
Note that jLabel1 is added below jPanel1 in the component tree. If you
drop the component in the wrong place, you can select it in the
component tree or in the designer and press the Delete key. Then re-add
it.
3 Click the middle of the label component in the designer, and drag it to
the center of the panel.
4 Select jLabel1 in the component tree and complete the following steps:
a Double-click the column to the right of the text property in the
Inspector and type Hello World! and press Enter.
“Hello World!” partially appears in the label. Don't worry if it
doesn't completely show in the label. You'll fix that after changing
the font.
b Click the column to the right of the font property to set the font.
Click the ellipsis button to open the Font dialog box.
c Choose Serif from the list of fonts and check Bold and Italic. Enter 28
in the Size box, then click OK.
d Resize jLabel1 by dragging the black handles until “Hello World!” is
completely visible.
4 Click Find.
The editor finds the selected text.
See also
• “Setting the classpath” at http://java.sun.com/j2se/1.3/docs/
tooldocs/tools.html
• “Basic tools” at http://java.sun.com/j2se/1.3/docs/tooldocs/
tools.html#basic
4 Change the Text property in the Inspector from jButton4 to Push Me. Press
Enter. Enlarge the button by dragging the black handles until “Push Me”
shows completely.
The Inspector should look like this:
5 Click the Inspector's Events tab to define what happens when jButton4
is pressed.
}
You can now enter code that defines the event.
7 Type the following code indicated in bold:
void jButton4_actionPerformed(ActionEvent e) {
jLabel1.setForeground(new Color(255,0,0));
}
Tip Use CodeInsight to complete the code for you. Type jLabel1. and wait
for the pop-up window or press Ctrl+spacebar to invoke it. If CodeInsight
fails to appear, check the settings on the CodeInsight page of Editor
Options (Tools|Editor Options). Type setfor to highlight
setForeground(Color) in the pop-up window or use the arrow keys. Press
Enter.
Now, when you run the application and push the “Push Me” button,
“Hello World!” should turn red.
8 Choose File|Save All.
9 Choose Project|Make Project “HelloWorld.jpx”.
10 Choose Run|Run Project.
11 Click the “Push Me” button. The color of the “Hello World!” text turns
red.
5 Accept the defaults in Steps 3 through 6 and click Next in each step.
6 Click Finish in Step 7 to close the Archive Builder.
An archive node called Application appears in the project pane. You can
modify this file by right-clicking and selecting Properties.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
/**
* Title: HelloWorld
* Description: This is the "Hello World" tutorial.
* Copyright: Copyright (c) 2001
* Company: MyCompany
* @author MyName
* @version 1.0
*/
/**Component initialization*/
private void jbInit() throws Exception {
image1 = new ImageIcon
(helloworld.HelloWorldFrame.class.getResource("openFile.gif"));
image2 = new ImageIcon(
helloworld.HelloWorldFrame.class.getResource("closeFile.gif"));
image3 = new ImageIcon
(helloworld.HelloWorldFrame.class.getResource("help.gif"));
//setIconImage(Toolkit.getDefaultToolkit().createImage
(HelloWorldFrame.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
border1 = BorderFactory.createLineBorder(Color.gray,2);
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Hello World");
statusBar.setText(" ");
jMenuFile.setText("File");
jMenuFileExit.setText("Exit");
jMenuFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuFileExit_actionPerformed(e);
}
});
jMenuHelp.setText("Help");
jMenuHelpAbout.setText("About");
jMenuHelpAbout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuHelpAbout_actionPerformed(e);
}
});
jButton1.setIcon(image1);
jButton1.setToolTipText("Open File");
jButton2.setIcon(image2);
jButton2.setToolTipText("Close File");
jButton3.setIcon(image3);
jButton3.setToolTipText("Help");
jPanel1.setBackground(Color.white);
jPanel1.setBorder(border1);
jPanel1.setLayout(gridBagLayout1);
jLabel1.setFont(new java.awt.Font("Serif", 3, 28));
jLabel1.setForeground(Color.blue);
jLabel1.setText("Hello World!");
jButton4.setText("Push Me");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton4_actionPerformed(e);
}
});
jToolBar.add(jButton1);
jToolBar.add(jButton2);
jToolBar.add(jButton3);
jMenuFile.add(jMenuFileExit);
jMenuHelp.add(jMenuHelpAbout);
jMenuBar1.add(jMenuFile);
jMenuBar1.add(jMenuHelp);
this.setJMenuBar(jMenuBar1);
contentPane.add(jToolBar, BorderLayout.NORTH);
contentPane.add(statusBar, BorderLayout.SOUTH);
contentPane.add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jLabel1, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(45, 125,
102, 110), 10, -6));
jPanel1.add(jButton4, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(46, 148,
0, 149), 16, 0));
}
/**File | Exit action performed*/
public void jMenuFileExit_actionPerformed(ActionEvent e) {
System.exit(0);
}
/**Help | About action performed*/
public void jMenuHelpAbout_actionPerformed(ActionEvent e) {
HelloWorldFrame_AboutBox dlg = new HelloWorldFrame_AboutBox(this);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height
-
dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.show();
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
jMenuFileExit_actionPerformed(null);
}
}
void jButton4_actionPerformed(ActionEvent e) {
jLabel1.setForeground(new Color(255,0,0));
}
}
import javax.swing.UIManager;
import java.awt.*;
/**
* Title: HelloWorld
* Description: This is the "Hello World" tutorial.
* Copyright: Copyright (c) 2001
* Company: MyCompany
* @author MyName
* @version 1.0
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
/**
* Title: HelloWorld
* Description: This is the "Hello World" tutorial.
* Copyright: Copyright (c) 2001
* Company: MyCompany
* @author MyName
* @version 1.0
*/
/**Component initialization*/
private void jbInit() throws Exception {
//imageLabel.setIcon
(new ImageIcon(HelloWorldFrame_AboutBox.class.getResource
("[Your Image]")));
this.setTitle("About");
setResizable(false);
panel1.setLayout(borderLayout1);
panel2.setLayout(borderLayout2);
insetsPanel1.setLayout(flowLayout1);
insetsPanel2.setLayout(flowLayout1);
insetsPanel2.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
gridLayout1.setRows(4);
gridLayout1.setColumns(1);
label1.setText(product);
label2.setText(version);
label3.setText(copyright);
label4.setText(comments);
insetsPanel3.setLayout(gridLayout1);
insetsPanel3.setBorder(BorderFactory.createEmptyBorder(10, 60, 10, 10));
button1.setText("Ok");
button1.addActionListener(this);
insetsPanel2.add(imageLabel, null);
panel2.add(insetsPanel2, BorderLayout.WEST);
this.getContentPane().add(panel1, null);
insetsPanel3.add(label1, null);
insetsPanel3.add(label2, null);
insetsPanel3.add(label3, null);
insetsPanel3.add(label4, null);
panel2.add(insetsPanel3, BorderLayout.CENTER);
insetsPanel1.add(button1, null);
panel1.add(insetsPanel1, BorderLayout.SOUTH);
panel1.add(panel2, BorderLayout.NORTH);
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
cancel();
}
super.processWindowEvent(e);
}
/**Close the dialog*/
void cancel() {
dispose();
}
/**Close the dialog on a button event*/
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button1) {
cancel();
}
}
}
Overview
It's important to remember when designing applets that browser support
for Java is limited. As of this writing, Internet Explorer and Netscape
support JDK 1.1.5. The browsers do not presently support Swing
components, introduced in JDK 1.1.7, although they may in the future. If
you are creating your applets with a more recent version of the JDK, you
must be very careful to use components that the browsers support. For
example, if you develop your applets strictly with AWT components, in
most cases your applets will run. There may be changes in the AWT
components (for example, JDK 1.1.x may have slightly different features
than JDK 1.3) and you may have to modify your applet code accordingly.
You can troubleshoot your applet in the browser by checking the Java
Console error messages. The safest way to design your applet is by using
AWT components and the JDK that the browser supports.
Note Browsers that support JDK 1.1 include Netscape 4.06 and later and
Internet Explorer 4.01 and later. JDK version support may vary by
platform.
Another option is to design your applets using the current JDK and Swing
components and provide your users with the Java Plug-in. This is usually
only possible within a controlled environment, such as a company
intranet. Browsers supported by the Java Plug-in, which provides the
browser with the Java 2 SDK 1.3 Runtime Environment (JRE), can run JDK
1.3-based applets. There are several additional steps involved in
developing applets that run with the Java Plug-in. Visit the Java Plug-in
Home Page at http://java.sun.com/products/plugin/index.html for
more information.
Although more recent browsers support only JDK 1.1.5, in this tutorial
you'll use JDK 1.3 and design only with AWT components, avoiding any
new JDK 1.3 features. The applet will still run, however, because you are
carefully selecting the components that you use. Older browsers that are
running on JDK 1.02 will not be able to run this applet, because event
handling changed in JDK 1.1. If you intend to use your applet on older
browsers, you need to use JDK 1.02 event handling.
Important For information on running JDK 1.1.x and 1.2/1.3 applets in JBuilder, see
“Running applets” in the Web Application Developer’s Guide.
For the complete applet code, see the “Applet source code” on page 10-34.
For in-depth information on applets and deployment, see “Working with
applets” and “Deploying Java programs” in Building Applications with JBuilder.
5 Accept the default paths in Step 2. Note where the compiled class files,
project files, and source files will be saved. For more information on
paths and how JBuilder saves files, see “Managing paths” on page 7-1.
Tip If you prefer to create your applet using an earlier version of the JDK,
change the JDK version in this step. Although JBuilder Personal does
not support JDK switching, you can edit the existing JDK in the
Configure JDKs dialog box (Tools|Configure JDKs). For JDK 1.1.x, you
also need to download the JDK 1.1.x-specific version of the JFC.
See also
• “Setting project properties” on page 7-5 for information on switching
or editing the JDK
• “Running applets” in the Web Application Developer’s Guide for
information on running applets in JBuilder
• “How JBuilder constructs paths” on page 7-14
• “Where are my files?” on page 7-17
6 Click Next to go to Step 3 of the wizard.
7 Make the following changes in the appropriate fields of Step 3:
The Automatic Source a Accept the Encoding and Automatic Source Packages defaults.
Packages option is a
feature of JBuilder SE
b Type Good Evening in the Title field of the class Javadoc fields.
and Enterprise. c Enter your name, company name, and a description of your applet in
the appropriate optional fields.
Note The information in the class Javadoc fields appears in the project
HTML file and as optional header comments in the source code.
See also
• “Defining and using parameters” at http://java.sun.com/docs/
books/tutorial/applet/appletsonly/param.html
8 Click Next to go to Step 3 of the Applet wizard.
9 Make the following changes in Step 3:
a Accept the default option, Generate HTML Page.
When you select this option, the HTML file that calls the applet is
created. This HTML file contains the <applet> tag and various
attributes.
b Enter Good Evening HTML Page in the Title field.
The title displays in the web browser window when the applet is
running.
c Accept the default values for all other attributes.
Step 3 of the Applet wizard should look like this:
The <applet> tag in the HTML file can include these attributes:
• codebase
This optional attribute specifies the path relative to the applet HTML
file that the browser searches to find any necessary class files. A
value of “.” specifies the same directory as the HTML file running
the applet. The codebase attribute is required when the class files are
in a different directory than the HTML file.
• code
This required attribute, which is automatically inserted by JBuilder's
Applet wizard, is the fully qualified class name (package name +
class name) of the applet class that contains the init() method. You'll
see it in the HTML file when it is generated. In this example, the fully
qualified class name is firstapplet.GoodEveningApplet.class.
• archive
This optional attribute, which is not included in the code generated
by the Applet wizard, is required when the applet is deployed in a
JAR, ZIP, or CAB file. Archive files must be in the directory specified
by codebase.
• name
This optional attribute names the applet.
• width/height
These required attributes determine the width and height of the
applet display area in pixels.
• hspace/vspace
These optional attributes determine the horizontal padding (left and
right margins) and vertical padding (top and bottom margins)
around the applet in pixels.
• align
This optional attribute determines the alignment of the applet on the
HTML page.
Important The values for codebase, code, archive, and name must be in quotation
marks and are case-sensitive.
See also
• “<applet> tag attributes” topic in the Web Application Developer’s
Guide
10 Click Finish to close the Applet wizard.
Note that two files are created and added to the project,
GoodEveningApplet.java and GoodEveningApplet.html.
GoodEveningApplet.java is open in the content pane.
Note In JBuilder SE and Enterprise editions, an automatic source package
node named firstapplet also appears in the project pane if the Enable
Source Package Discovery And Compilation option is enabled on the
3 Choose File|Save All to save the source files and the project file.
Note By default, JBuilder saves the source files to:
/<home>/jbproject/FirstApplet/src/firstapplet/
The applet HTML file is saved to the classes directory:
/<home>/jbproject/FirstApplet/classes/
The class files, after compiling, are saved to the output path:
/<home>/jbproject/FirstApplet/classes/firstapplet/
JBuilder always follows the package hierarchy when saving files. In this
example, the source and class files are saved within a firstapplet
directory on the source and output paths to reflect the firstapplet
package structure. These paths are set for the project by the Project
wizard and can be viewed in the Project Properties dialog box (Project|
Project Properties). In this tutorial, you accepted the default JBuilder
paths in Step 2 of the Project wizard.
You can change the applet's run settings on the Applet tab of the Run
page of the Runtime Properties dialog box. To access this dialog box,
open the Project Properties dialog box (Project|Project Properties),
select the Run tab, select the GoodEveningApplet on the Run page, and
click Edit. The settings on the Applet tab control the behavior of the
Run menu and the Run icon on the tool bar. Choose the Main Class
option to run your applet in JBuilder's AppletTestbed. Choose the
HTML option to run your applet in Sun's appletviewer. When you use
the Applet wizard to create your applet, the Main Class option is set by
default.
Important Applets run from the HTML file, which calls the class containing the
init() method, not from the .java file. Any attempt to run the .java file
results in an error message (unless the Can Run Standalone option was
selected in Step 1 of the Applet wizard):
java.lang.NoSuchMethodError: main
Exception in thread "main"
2 Choose Exit in the “Good Evening” applet to close it.
3 Right-click the GoodEveningApplet tab in the message pane and select
Remove “GoodEveningApplet” Tab to close any runtime messages.
See also
• “Using layout managers” in Designing User Interfaces
• “Creating a UI with nested layouts” inDesigning User Interfaces
4 Choose the AWT tab on the component palette at the top of the UI
designer.
You might need to scroll to the right on the component palette to find
the AWT tab. AWT components, unlike Swing components, are
supported by most web browsers.
Caution The UI designer always opens with the Swing components on the first
page of the component palette. If you select these Swing components
by mistake, your applet won't run in the web browsers. Be very careful
to choose components from the AWT page of the palette.
5 Add two panels to the this panel. The top panel will contain a drop-
down list of languages to select from and a label to identify the list. The
bottom panel will contain “Good Evening” in various languages.
a Shift+Click the AWT Panel component, java.awt.Panel, on the
component palette.
Shift+Click allows you to drop the same component multiple times
without having to select it each time from the component palette.
Now you can add multiple panels to this.
Tip Place the cursor over a component to see its name in a tool tip.
b Click twice on this in the component tree in the structure pane to
add two panels. panel1 and panel2 are added below this in the
component tree.
c Click the Selection Tool on the left side of the component palette to
disable the component selection.
d Check the constraints property for the panels in the Inspector. The
top panel in your design should be North and the bottom panel
should be Center. To check the constraints property,
1 Select a panel in the component tree or in the UI designer. If a
component is selected in the designer, small nibs show at each
corner of the component.
2 Confirm that the constraints property in the Inspector is set to
North for the top panel and Center for the bottom panel. If not,
click the column to the right of the constraints property and
choose the correct constraint from the drop-down list.
e Rename the top panel to upper:
1 Select the top panel in the component tree or the designer and
double-click the column to the right of the name property in the
Inspector.
try {
jbinit();
}
catch(Exception e) {
e.printStackTrace();
}
}
Tip Use CodeInsight to complete the code for you. Enter choice1. and
wait for the pop-up window or press Ctrl+spacebar to invoke it. Be
sure to include the dot (.) after choice1. Use the arrow keys to select
addItem(String) from the pop-up window. Press Enter. You can
If there are any syntax errors in your code, an Errors folder appears in
the structure pane as you type in the editor. Open the folder and select
the error message to highlight the error in the source code.
See also
• “About error and warning messages” in Building Applications with
JBuilder
Next, you'll hook up the event to the language choice. When you select
a language from the drop-down list Choice component, “Good
Evening” appears in the cardLayout panel in the selected language.
2 Hook up the Choice list events as follows:
a Return to the UI designer.
b Select choice1 located under upper in the component tree.
c Select the Events tab in the Inspector.
d Double-click to the right of the itemStateChanged event.
JBuilder generates the method code and takes you to the source code
with the cursor inserted in the method.
void choice1_itemStateChanged(ItemEvent e) {
}
e Add the following code indicated in bold to connect the correct
language panel to the language choice:
void choice1_itemStateChanged(ItemEvent e) {
if ("English".equals(choice1.getSelectedItem())){
cardLayout1.show(lower, "panel1");
}
else if ("German".equals(choice1.getSelectedItem())){
cardLayout1.show(lower, "panel2");
}
else if ("Pig Latin".equals(choice1.getSelectedItem())){
cardLayout1.show(lower, "panel3");
}
else if ("Swedish".equals(choice1.getSelectedItem())){
cardLayout1.show(lower, "panel4");
}
else if ("Australian".equals(choice1.getSelectedItem())){
cardLayout1.show(lower, "panel5");
}
}
Tip You can use code templates to generate code. Type if and press Ctrl+J
to access the code templates pop-up window. Use the arrow keys to
navigate the selections. Select the if-else if template and press Enter.
The code is generated:
if () {
}
else if{
}
3 Choose File|Save All.
4 Run the applet by right-clicking GoodEveningApplet.html in the project
pane and selecting Run.
The “Good Evening” applet runs in Sun's appletviewer:
If there are any errors, they appear in the message pane at the bottom of
the AppBrowser. Select an error message and press F1 for Help. Select
the error message to highlight the code in the editor. Sometimes the
error may be before or after the highlighted line of code. Fix the errors,
save the project, and run the applet again.
5 Test the drop-down list. The language selected from the list should
match the language on the panel below it.
6 Exit the applet.
Now, add a button label and a button event for button1 on panel5. When
you push the button, the “Gudday, Mate” text on label6 changes to red.
1 Add a button label and a button event as follows:
a Switch to the UI designer.
b Select button1 on panel5 and change the button's Label property on the
Properties page of the Inspector from button1 to Push Me. Press Enter.
Notice how the button automatically resizes to fit the text.
c Click the Inspector's Events tab to define what happens when button1
is pressed.
d Double-click the column to the right of the ActionPerformed event.
JBuilder switches to the editor where the following skeleton code has
been added for the ActionPerformed event just below the if-else if
statements.
void button1_actionPerformed(ActionEvent e) {
}
Tip Double-clicking the button in the designer has the same effect.
Now, enter the code that defines the button event which will change
“Gudday, Mate” to red.
e Type the following code indicated in bold:
void button1_actionPerformed(ActionEvent e) {
label6.setForeground(new Color(255,0,0));
}
2 Save the project.
3 Run the applet and select “Australian” from the drop-down list. Click
the “Push Me” button. “Gudday, Mate” should turn red.
Your applet should look similar to this:
See also
• “Deploying Java programs” in Building Applications with JBuilder
• Step 16 of the JBuilder tutorial “Building a Java text editor - Deploying
the Text Editor application” in Designing User Interfaces
Depending on the edition of JBuilder you have, there are several tools for
deploying your applet:
• Java jar tool available with the JDK
• JBuilder's Archive Builder, available in SE and Enterprise
Note The JDK must be on your path. If it isn't, use the following command:
/<jbuilder>/<jdk>/bin/jar cvf GoodEvening.jar -C classes firstapplet
Where <jbuilder> represents the name of the JBuilder directory and
<jdk> represents the name of the JDK directory. For example,
See also
• “Using JAR Files: The Basics” at http://java.sun.com/docs/books/
tutorial/jar/basics/index.html
• “jar-The Java Archive Tool” at http://java.sun.com/j2se/1.3/docs/
tooldocs/tools.html#basic
• “Deploying Java programs” in Building Applications with JBuilder
5 Select Applet JAR from the Archive Type drop-down list in Step 1 and
click Next to continue to Step 2.
Note Select the Applet ZIP archive type if you are developing applets for
older browsers that do not support JAR files.
6 Accept the default name of Applet JAR in the name field.
7 Click the ellipsis button next to the File field and browse to the /<home>/
jbproject/applets/ directory.
8 Change the JAR file name in the File Name field to GoodEvening.jar and
click OK.
Step 2 should look like this:
See also
• “Using the Archive Builder” in Building Applications with JBuilder
• “Deploying Java programs” in Building Applications with JBuilder
Tip If you have multiple JAR files for your applet, list them separated by a
comma as shown here:
archive="file1.jar, file2.jar"
Important Some older web browsers do not support JAR files and multiple listings
of archive files but do support a single ZIP file in the archive attribute.
Next, add a message that tells users without Java-enabled browsers that
their browsers do not support Java; therefore, they can't see the applet.
2 Enter the following message between the open and close <applet> tags:
You need a Java-enabled browser running JDK 1.1.x or greater to view this
applet.
The <applet> tag looks like this:
<applet
codebase = "."
code = "firstapplet.GoodEveningApplet.class"
archive = "GoodEvening.jar"
name = "TestApplet"
width = 400
height = 300
hspace = 0
vspace = 0
align = top
>
You need a Java-enabled browser running JDK 1.1.x or greater to view this
applet.
</applet>
Any web browser that does not support Java ignores the <applet> tags
and displays everything between the tags. Because a Java-enabled
browser recognizes the <applet> tags, anyone with a Java-enabled
browser will see the applet and not the message.
Important Before saving the HTML file, check the codebase and code values again.
If these values are incorrect, the applet won't run. Remember that the
codebase value is the location of the applet code (class or JAR file) in
relation to the HTML file. The value, “.”, means the class file is in the
same directory as the HTML file. The code value must be the fully
qualified class name for the applet, including the package name.
3 Save and close the file.
4 Copy the modified GoodEveningApplet.html from the project's classes
directory to the applets directory. The applets directory should contain
two files, GoodEveningApplet.html and GoodEvening.jar.
Caution Remember, JBuilder creates two HTML files: the project notes HTML file,
FirstApplet.html, located at the root of the project directory and the applet
HTML file containing the <applet> tag, GoodEveningApplet.html, located in
the project src directory. Do not copy FirstApplet.html instead of
GoodEveningApplet.html to the applets directory or your applet will not run.
2 Test the applet in various browsers. If the applet fails to load, check that
the browser is Java-enabled. Also check the browser's Java Console for
error messages.
To open the Java Console:
• Select Communicator|Tools|Java Console in Netscape.
• Select View|Java Console in Internet Explorer.
3 Correct any errors, redeploy your applet, and test again in the
browsers.
See also
• “Testing applets” in the Web Application Developer’s Guide
<applet
codebase = "."
code = "firstapplet.GoodEveningApplet.class"
archive = "GoodEvening.jar"
name = "TestApplet"
width = 400
height = 300
hspace = 0
vspace = 0
align = top
>
You need a Java-enabled browser running JDK 1.1.x or greater to view this
applet.
</applet>
</body>
</html>
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
this.setLayout(borderLayout1);
upper.setBackground(Color.orange);
lower.setBackground(Color.magenta);
lower.setLayout(cardLayout1);
panel1.setLayout(borderLayout2);
panel2.setLayout(borderLayout3);
panel3.setLayout(borderLayout4);
panel4.setLayout(borderLayout5);
panel5.setLayout(flowLayout1);
panel1.setBackground(new Color(190, 173, 255));
panel2.setBackground(new Color(83, 182, 255));
panel3.setBackground(new Color(255, 149, 66));
panel4.setBackground(new Color(239, 107, 140));
panel5.setBackground(new Color(17, 198, 99));
label1.setFont(new java.awt.Font("Serif", 1, 20));
label1.setForeground(Color.blue);
label1.setText("Select a language");
label2.setFont(new java.awt.Font("Dialog", 1, 24));
label2.setForeground(Color.black);
label2.setText("Good Evening");
label3.setFont(new java.awt.Font("Dialog", 1, 24));
label3.setForeground(Color.black);
label3.setText("Guten Abend");
label4.setFont(new java.awt.Font("Dialog", 1, 24));
label4.setForeground(Color.black);
label4.setText("Oodgay vening eay");
label5.setFont(new java.awt.Font("Dialog", 1, 24));
label5.setForeground(Color.black);
label5.setText("God Kvall");
choice1.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(ItemEvent e) {
choice1_itemStateChanged(e);
}
});
label6.setFont(new java.awt.Font("Dialog", 1, 24));
label6.setForeground(Color.black);
label6.setText("Gudday, Mate");
button1.setLabel("Push Me");
button1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
button1_actionPerformed(e);
}
});
this.add(lower, BorderLayout.CENTER);
lower.add(panel1, "panel1");
panel1.add(label2, BorderLayout.NORTH);
lower.add(panel2, "panel2");
panel2.add(label3, BorderLayout.SOUTH);
lower.add(panel3, "panel3");
panel3.add(label4, BorderLayout.EAST);
lower.add(panel4, "panel4");
panel4.add(label5, BorderLayout.WEST);
lower.add(panel5, "panel5");
panel5.add(button1, null);
panel5.add(label6, null);
this.add(upper, BorderLayout.NORTH);
upper.add(label1, null);
upper.add(choice1, null);
}
/**Start the applet*/
public void start() {
}
/**Stop the applet*/
public void stop() {
}
/**Destroy the applet*/
public void destroy() {
}
/**Get Applet information*/
public String getAppletInfo() {
return "Applet Information";
}
/**Get parameter info*/
public String[][] getParameterInfo() {
return null;
}
void choice1_itemStateChanged(ItemEvent e) {
if ("English".equals(choice1.getSelectedItem())){
cardLayout1.show(lower, "panel1");
}
else if ("German".equals(choice1.getSelectedItem())){
cardLayout1.show(lower, "panel2");
}
else if ("Pig Latin".equals(choice1.getSelectedItem())){
cardLayout1.show(lower, "panel3");
}
else if ("Swedish".equals(choice1.getSelectedItem())){
cardLayout1.show(lower, "panel4");
}
else if ("Australian".equals(choice1.getSelectedItem())){
cardLayout1.show(lower, "panel5");
}
}
void button1_actionPerformed(ActionEvent e) {
label6.setForeground(new Color(255,0,0));
}
}
If you don't have the necessary access to place a project into your version
control system, but you still want to see the version control aspects of the
history view, you can use the installation of CVS provided with your
JBuilder installation. CVS allows you to create a local repository that's
completely under your control. For more information on version control
in JBuilder, see Team Development Using JBuilder. For more information on
CVS specifically, see “CVS in JBuilder” in Team Development Using
JBuilder.
3 Put the cursor at the end of row 27. The text in this row reads import
javax.swing.UIManager;.
4 Press Enter at the end of row 27 to add a line below it.
5 Type import java.applet.*; in row 28.
6 Choose File|Save File or click the Save File icon to save the file. This
generates a backup type of version to view later.
Backup versions are kept in the bak subdirectory of this project's
directory. By default, JBuilder keeps the 5 most recent backup versions.
To change the backup level (the number of backup versions JBuilder
maintains), choose Tools|Editor Options, select the Editor page if it's
not automatically selected, and adjust the Backup Level slider in the top
third of the Editor page. You can have up to 30 backups stored in your
bak directory.
Version control users: 7 Change import java.applet.*; to import java.applet.Applet; and commit
the file. Enter the comment Changed import.java.applet.* to
import.java.Applet. This generates a version control type of version to
view later.
8 Change import java.applet.*; to import java.applet.Applet; and save the
file.
9 Go to line 31, which reads boolean packFrame = false;.
10 Change false to true.
11 Save the file.
Make one more change, but don't save it:
12 Put the cursor in row 35, column 23, which reads WelcomeFrame frame =
new WelcomeFrame;
13 Change the object name frame to frame2.
Your source now looks like this:
This image was adjusted to highlight all of the changes made so far.
The revision list at the top lists versions by revision number, most
recent revisions at the top of the list.
The source of the most recent version is displayed in the source viewer
below the revision list.
Note the information in the status bar: file name, date and time, and
row and column notation.
2 Click a file version to see the version in the source viewer. JBuilder
retrieves the requested version from wherever it's stored, either in your
own file system or in version control.
3 Click the head of the icon column to sort the versions by revision type.
Notice the different icons for the different types of versions used: local
4 Click the Date column head to sort the versions by reverse order of
their dates of change.
5 Select the top item in the list (~1~ Local Backup). This version appears in
the source pane below the revision list.
6 Click the Synchronize Scrolling button.
7 Scroll to row 30, with the boolean packFrame statement.
8 Select the entire statement and copy it:
You can use the History Contents page to view all stored versions of a file
and use the Revert and Synchronize Scrolling buttons. This page protects
prior file versions by making them read-only, and it supports copying and
pasting from prior versions into your current source code.
JBuilder Personal users, this is the conclusion of your tutorial. For more
information on the history view and the History pages, see Chapter 8,
“Comparing files and versions.”
In the status area at the bottom, the Diff page tells you how many
blocks of differences there are in your comparison.
Version control users: To see all changes made to the repository since you started working,
select the original repository version in the From area and the file
version with the highest revision number in the To area.
2 Click the Refresh button. This retrieves any new versions from the
repository. There are none, so your revision list won't change.
3 Press Alt + n to go to the next block of difference.
4 Click the diff arrows on the left of the status bar at the bottom of the
Diff page to move from one block to another.
5 Click the Undo Change button. An option called Undo Above Changes
appears.
6 Click the option. Line 28 now reads import java.applet.*;.
import java.applet.Applet; disappears and the diff block is resolved.
In the History Diff page, you can view differences between all available
versions of a file, sort the versions in many ways, reconcile differences
between the buffer and any other version, and easily navigate among the
differences between two versions.
JBuilder SE users, this is the conclusion of your tutorial. For more
information on the history view and the History pages, see Chapter 8,
“Comparing files and versions.”
5 Click the Revert button. The Revert Confirmation dialog box appears:
Reverting to a previous version of the file makes the chosen version the
current version again. If the file is under version control or if your
backup level is high enough to hold all the versions, all intermediate
versions are kept.
Version control users: The file reversion needs to be checked into version control like any
other file change.
6 Click OK.
You have used the Contents, Info, and Diff pages in the history view. You
know how to view different file revisions, find and view comments and
labels of file revisions, and how to examine differences between various
backup, buffer, repository, and workspace versions of a file.
Index I-1
customizing display 4-36
JBuilder's editor 4-32 Java structure 4-44
JBuilder's IDE 4-45 editor, using 4-18
EJB Designer options 4-55
D encoding
setting 6-6
Debug page (Project Properties dialog box) 4-14 error messages
debugger 4-14 viewing and finding 4-10
debugging 4-30 ExpressionInsight 4-30
using -classic option 7-7 expressions
default project auto-evaluating 4-30
properties 4-8
deleting 6-16 F
designers
column designer 5-1 Favorites 4-18
menu designer 5-1 file types
UI designer 5-1 setting options 4-48
developer support 1-5 files
Diff page 8-6 comparing any two 8-1, 8-2
diffs location 7-17
comparing any two files 8-2 See also project files
display options 4-36 opening outside of project 6-16
CodeInsight 4-40 renaming 6-16
displaying switching 6-10
project files 7-18 viewing in JBuilder 6-10
doc path 7-17 viewing project files 7-18
documentation viewing structure 4-8
JBuilder titles 2-1 Find Classes 4-17
documentation conventions 1-2 Find Definition 4-30
Macintosh-specific 1-4 Find Definition command 4-22
platform conventions 1-4 Find References command 4-23
drilling down finding classes 4-17
in file structure 4-8, 4-9 finding references to
code symbol 4-23
E finding text 4-22
fonts
editing the JDK 7-7 JBuilder documentation conventions 1-2
editor
code templates 4-30 G
context menu 4-21
customizing 4-32 getting help 3-3
customizing the editor 4-33
Find Definition command 4-22 H
Find References command 4-23
Javadoc tips 4-23 help
keymaps 4-19 getting help 3-3
printing source code 4-25 using online 3-3
searching 4-22 hierarchical views 4-8
splitting view 4-21 history view
todo tags 4-25 Contents page 8-5
editor emulations 4-19 Diff page 8-6
editor options 4-32, 4-33 icons 8-4
code templates 4-43 Info page 8-7
CodeInsight 4-38, 4-40 overview 8-4
color 4-37
Index I-3
display 4-36 Step 2-setting paths, libraries, JDK 6-4
editor 4-33 Step 3-general project settings 6-6
EJB Designer 4-55 projects 6-1
file types 4-48 adding files or packages 6-14
Java structure 4-44 adding files, packages 6-15
Run/Debug 4-51 adding folders 6-14
UML 4-53 adding ZIP or JAR files 7-1
Web 4-49 closing 6-11
XML 4-50 creating and adding to 6-13
organizing projects 6-14 creating new 6-2
See also projects creating with Project For Existing Code
out path 7-15 wizard 6-8
creating with Project wizard. 6-2
P opening 6-12
removing from 6-15
packages 7-11 renaming 6-16
class reference in 7-13 saving 6-11
naming conventions 7-14 saving multiple 6-18
parameter lists 4-29 setting properties 4-7, 7-5
ParameterInsight 4-29 switching between 6-17
options 4-40 using multiple projects 6-17
ParameterInsight options 4-42 viewing files 6-10
paths 7-1, 7-14 properties
See also setting paths setting project properties 4-7
class file locations 7-13
compiling, running, debugging 7-18 Q
Java file locations 7-12
printing quick links
from the editor 4-25 Favorites 4-18
source code 4-25
project R
setting general parameters 6-6
project files 6-1 references
paths 7-17 from libraries 6-6
saving 6-11 referencing classes 7-13
setting paths 7-14 Release Notes 4-1
viewing 7-18 resizing content pane 4-13
viewing structure 4-8 revision management
paths see history view 8-4
See also setting paths Run/Debug options 4-51
Project For Existing Code wizard 6-8
project pane S
context menu 4-6
saving multiple projects 6-18
filtering packages 4-6
search commands 4-22
project toolbar 4-5
Search menu 4-22
searching 4-5
searching 4-16
project paths
in AppBrowser 4-16
setting 6-4
in project pane 4-5
project properties
in the editor 4-23
default 4-8
in trees 4-16
project template
using Find Definition 4-22
setting 6-2
with Find References 4-23
Project wizard
with incremental typing 4-16
creating new projects 6-2
searching classes 4-17
Step 1-setting root, type, and template 6-2
See also Find Classes
Index I-5
I-6 Introducing JBuilder