0% found this document useful (0 votes)
15 views

Introjb

Uploaded by

davidlister79
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Introjb

Uploaded by

davidlister79
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 202

Introducing JBuilder ™

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

Introducing JBuilder provides detailed information about the integrated


development environment (IDE). It also explains the concept of projects
and libraries and how JBuilder uses paths when working with projects.
Learn how to use the JBuilder editor, CodeInsight, JBuilder wizards, and
many other productivity features to quickly create your source code. Find
information about JBuilder's Help Viewer and how to find answers to
your questions in JBuilder's extensive documentation. Several
introductory tutorials are also provided to help you learn how to use
JBuilder.
Introducing JBuilder contains the following chapters:
• Chapter 2, “Learning more about JBuilder”
Describes the JBuilder documentation by JBuilder edition and provides
links to additional resources.
• Chapter 3, “Learning more about Java”
Provides a list of glossaries and books on the Java language.
• Chapter 4, “The JBuilder environment”
Introduces the JBuilder integrated development environment (IDE)
user interface and discusses such topics as: working in the
AppBrowser, using the editor, customizing JBuilder, coding shortcuts,
and using wizards.
• Chapter 5, “Automating code development”
Describes how to generate code automatically using the visual design
tools and JBuilder's many wizards.

Introduction 1-1
Documentation conventions

• Chapter 6, “Creating and managing projects”


Explains how to create and manage projects and files in JBuilder and
how to use the AppBrowser to perform management tasks.
• Chapter 7, “Managing paths”
Discusses essential JBuilder concepts: libraries, project properties, and
how JBuilder constructs paths and finds files when executing various
processes, such as compiling and debugging.
• Chapter 8, “Comparing files and versions”
Describes the pages and features available from the History tab in the
content pane. Describes the features available in the different editions
of JBuilder and how they work both with and without a version control
system in place.
• Tutorials:
• Chapter 9, “Tutorial: Building an application”
Explains how to create a simple “Hello World” application.
• Chapter 10, “Tutorial: Building an applet”
Explains how to create an AWT applet.
• Chapter 11, “Tutorial: Using the history view”
Explains the use of the history view.
For more information on JBuilder and its many features, visit the Borland
JBuilder web site at http://www.borland.com/jbuilder.

Documentation conventions
The Borland documentation for JBuilder uses the typefaces and symbols
described in the table below to indicate special text.

1-2 Introducing JBuilder


Documentation conventions

There are special considerations on the Macintosh platform. Please see


“Note to Macintosh users” on page 1-4 for more information.

Table 1.1 Typeface and symbol conventions


Typeface Meaning
Monospace type Monospaced type represents the following:
• text as it appears onscreen
• anything you must type, such as “Enter Hello World in the
Title field of the Application wizard.”
• file names
• path names
• directory and folder names
• commands, such as SET PATH, CLASSPATH
• Java code
• Java data types, such as boolean, int, and long.
• Java identifiers, such as names of variables, classes, interfaces,
components, properties, methods, and events
• package names
• argument names
• field names
• Java keywords, such as void and static
Bold Bold is used for java tools, bmj (Borland Make for Java), bcj
(Borland Compiler for Java), and compiler options. For example:
javac, bmj, -classpath.
Italics Italicized words are used for new terms being defined, for book
titles, and occasionally for emphasis.
Keycaps This typeface indicates a key on your keyboard, such as “Press
Esc to exit a menu.”
[] Square brackets in text or syntax listings enclose optional items.
Do not type the brackets.
<> Angle brackets in text or syntax listings indicate a variable string;
type in a string appropriate for your code. Do not type the angle
brackets.
Angle brackets are also used in HTML tags.
Additionally, angle brackets are used for JBuilder and JDK
directories. For example, <jbuilder> is a placeholder for the
current version of the JBuilder directory, such as jbuilder7, and
<.jbuilder> represents the current JBuilder directory for storing
JBuilder settings, such as .jbuilder7. Also, <jdk> is used as a
placeholder for the current JDK directory.
... In code examples, an ellipsis indicates code that is missing from
the example. On a button, an ellipsis indicates that the button
links to a selection dialog box.

Introduction 1-3
Documentation conventions

JBuilder is available on multiple platforms. See the table below for a


description of platforms and directory conventions used in the
documentation.

Table 1.2 Platform conventions and directories


Item Meaning
Paths All paths in the documentation are indicated with a forward
slash (/).
For Windows platforms, use a backslash (\).
Home directory The location of the home directory varies by platform and is
indicated with a placeholder, <home>.
• For UNIX and Linux, the home directory can vary. For
example, it could be /user/<username> or /home/<username>
• For Windows 95/98, the home directory is C:\Windows
• For Windows NT, the home directory is C:\Winnt\
Profiles\<username>
• For Windows 2000, the home directory is C:\Documents
and Settings\<username>
<jbuilder> directory The <jbuilder> directory contains the JBuilder installation,
including program files, documentation, libraries, JDK,
samples, and other files. This directory is named after the
current version of JBuilder, such as jbuilder7.
<.jbuilder> directory The <.jbuilder> directory, where JBuilder settings are stored,
is located in the home directory. This directory is named
after the current version of JBuilder, such as .jbuilder7.
jbproject directory The jbproject directory, which contains project, class,
source, backup, and other files, is located in the home
directory. JBuilder saves files to this default path.
<jdk> directory The <jdk> directory represents the current Java Development
Kit. For example, jbuilder7/jdk1.3/ would be represented in
the documentation as <jbuilder>/<jdk>/.
Screen shots Screen shots reflect the Metal Look & Feel on various
platforms.

Note to Macintosh users


JBuilder is designed to support Macintosh OS X so seamlessly that
JBuilder will have the look and feel of a native application. The Macintosh
platform has conventions of appearance and style that vary from
JBuilder’s own; where that happens, JBuilder supports the Mac look and
feel. This means that there are some variations between what JBuilder
looks like on the Mac and how it is presented in the documentation. For
instance, this documentation uses the word “directory” where Mac uses
the word “folder.” For further information on Macintosh OS X paths,
terminology, and UI conventions, please consult the documentation that
comes with your OS X installation.

1-4 Introducing JBuilder


Contacting Borland developer support

Contacting Borland developer support


Borland offers a variety of support options. These include free services on
the Internet, where you can search our extensive information base and
connect with other users of Borland products. In addition, you can choose
from several categories of support, ranging from support on installation of
the Borland product to fee-based consultant-level support and extensive
assistance.
For more information about Borland’s developer support services, see our
web site at http://www.borland.com/devsupport/, call Borland Assist at
(800) 523-7070, or contact our Sales Department at (831) 431-1064.
When contacting support, be prepared to provide complete information
about your environment, the version of the product you are using, and a
detailed description of the problem.
For support on third-party tools or documentation, contact the vendor of
the tool.

Online resources
You can get information from any of these online sources:

World Wide Web http://www.borland.com/


FTP ftp.borland.com
Technical documents available by anonymous ftp.
Listserv To subscribe to electronic newsletters, use the
online form at:
http://www.borland.com/contact/listserv.html
or, for Borland’s international listserver,
http://www.borland.com/contact/intlist.html

World Wide Web


Check www.borland.com regularly. The JBuilder Product Team posts
white papers, competitive analyses, answers to frequently asked
questions, sample applications, updated software, updated
documentation, and information about new and existing products.
You may want to check these URLs in particular:
• http://www.borland.com/jbuilder/ (updated software and other files)
• http://www.borland.com/techpubs/jbuilder/ (updated
documentation and other files)

Introduction 1-5
Contacting Borland developer support

• http://community.borland.com/ (contains our web-based news


magazine for developers)

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.

1-6 Introducing JBuilder


Chapter

Learning more about JBuilder


Chapter2
2
The JBuilder documentation set
Documentation is available in the following ways:

Document Description Print PDF Help HTML


All editions:
Introducing JBuilder Tells what's new in this version of JBuilder and introduces X X X X
the development environment. Also explains JBuilder
essentials: projects, libraries, and how JBuilder uses project
paths during such processes as searching, compiling,
running, and debugging. Includes information and a
tutorial on version handling. Provides several step-by-step
tutorials for creating your first application and applet with
JBuilder.
Building Applications Explains how to create JavaBeans, compile, debug, deploy, X X X X
with JBuilder and internationalize programs in JBuilder. Discusses
JBuilder's Javadoc, code visualization, code refactoring,
and unit testing features. Also includes information on
command-line tools, error messages, and how to migrate
applications from other Java development tools.
Designing User Explains how to design user interfaces and use layout X X X X
Interfaces managers. Includes step-by-step tutorials for creating user
interfaces using JBuilder's visual design tools.
Developing Provides conceptual information about the architecture of X X X
OpenTools some of JBuilder's subsystems and it's OpenTools API for
building your own add-ins.
OpenTools API Provides reference documentation for the JBuilder X X
Reference OpenTools API.
Getting Started with Provides an overview of the Java programming language, X X X X
Java class libraries, and editions.

Learning more about JBuilder 2-1


Additional resources

Document Description Print PDF Help HTML


1.
JDK 1.3 API reference documentation for the Sun Java X
documentation Development Kit (JDK).
You can access this documentation in one of two ways:
• Choose Help|Java Reference.
• Choose the Doc tab in the content pane when viewing a
JDK file.
1.
Java Language Contains version 2.0 of the Java Language Specification. X
Specification
Context-sensitive Provides information related specifically to the current X
online help JBuilder user interface element.
SE and Enterprise editions:
Team Development Discusses version management and explains how to use X X X X
Using JBuilder JBuilder's interfaces with three major version control
systems as well as JBuilder's own version handling tools.
Enterprise edition:
Enterprise JavaBeans Explains how to develop and debug Enterprise JavaBeans X X X X
Developer’s Guide applications.
Web Application Discusses the technologies used for web development in X X X X
Developer’s Guide JBuilder.
XML Application Discusses the technologies used for XML development in X X X X
Developer’s Guide JBuilder.
Database Application Discusses JBuilder's DataExpress database architecture. X X X X
Developer’s Guide Explains the relationships between the main DataExpress
data components and classes, and how to use them to
create your database applications.
JDataStore Explains how to make effective use of JDataStore X X X X
Developer’s Guide functionality. JDataStore is a high-performance,
small-footprint, all Java database.
DataExpress Provides detailed information online about all the X X
Component Library borland.com value-added, data-aware components,
Reference classes, properties, methods, and events.

1. This documentation is also available from the Java Developer Connection at


http://developer.java.sun.com/developer/infodocs/.

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.”

2-2 Introducing JBuilder


Chapter

Learning more about Java


Chapter3
3
Resources on the Java language abound. This list is only partial, and to
some degree reflects the libraries and bookmarks of the JBuilder
developers.

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.

Books Authors Audience


Java for the World Wide Web: Dori Smith no
Visual Quickstart Guide programming
(Peachpit Press) background
Java: First Contact Roger Garside no
(Course Technology) and John Mariani programming
background
A Little Java, A Few Patterns Mattias Felleisen novice to
(MIT Press) and Daniel P. Friedmens advanced1

Learning more about Java 3-1


Books

Books Authors Audience


Beginning Java 2 Ivor Horton novice
(Wrox Press)
Learning Java Patrick Niemeyer novice
(O'Reilly) and Jonathan Knudsen
Core Java 2, Volume 1: Cay S. Horstmann intermediate to
Fundamentals and Gary Cornell advanced
(Prentice Hall)
Just Java 2 Peter van der Linden intermediate to
(Prentice Hall) advanced
Thinking in Java Bruce Eckel intermediate to
(Prentice Hall) advanced
Effective Java Programming Josh Bloch intermediate to
Language Guide advanced
(Addison Wesley Longman,
Inc.)
The Java Programming Ken Arnold, advanced-
Language James Gosling, intermediate to
(Addison-Wesley) and David Holmes advanced
The Complete Java 2 Simon Roberts, et al. advanced
Certification Study Guide
(Sybex, Inc.)
Data Structures and Algorithms Mitchell Waite advanced
in Java and Robert Lafore
(Waite Group Press)

1. Philosophical in tone. Good for understanding concepts: not good for “how-to”.

Books Authors Topic


Java in a Nutshell David Flanagan quick reference
(O'Reilly) and Daniel P. Friedmens
Java Class Libraries Reference Patrick Chan, Java classes
(Addison Wesley) Rosanna Lee,
and Doug Kramer
Java Developer Almanac Patrick Chan Java classes
(Addison Wesley Longman, quick reference
Inc.)
Graphic Java 2: Mastering the David M. Geary Swing
JFC, Volume 2: Swing
(Prentice Hall)
UML Distilled: A Brief Guide to Martin Fowler UML
the Standard Object Modeling and Kendall Scott
Language
(Addison Wesley Longman)
Refactoring: Improving the Martin Fowler Refactoring
Design of Existing Code
(Addison Wesley)

3-2 Introducing JBuilder


Using JBuilder's online help

Books Authors Topic


Developing JavaBeans Robert Englander JavaBeans
(O'Reilly)
Enterprise JavaBeans Richard Monson-Haefel network
(O'Reilly) JavaBeans
Java 2 Networking Justin Couch network
(McGraw Hill) programming
The Java Virtual Machine Tim Lindholm network
Specifications and Frank Yellin programming
(Addison-Wesley)
Java Programming with CORBA Andreas Vogel network
(John Wiley and Sons, Inc.) and Keith Duddy programming
JDBC Database Access with Graham Hamilton, JDBC
Java: a Tutorial and Annotated Maydene Fisher,
Reference and Rick Cattell
(Addison-Wesley)
Inside Servlets: Server-Side Dustin R. Callaway servlets
Programming for the Java
Platform
(Addison-Wesley)
Java: Servlet Programming Jason Hunter servlets
(O'Reilly) and William Crawford

Using JBuilder's online help


JBuilder displays online help topics in the Help Viewer. Topics can also be
displayed in the AppBrowser or in a web browser.

How to get Help


You can get help from within JBuilder in the following ways:
• From the IDE:
• Help viewer: choose Help|Help Topics from the JBuilder main
menu to open the Help Viewer.
• Context help: click the Help button displayed on a dialog box, or
press F1 from inside a pane, menu, or a dialog box with a Help
button.
• Class reference: Choose Search|Find Classes, enter a class name,
then click the Doc tab.

Learning more about Java 3-3


Using JBuilder's online help

• 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.

3-4 Introducing JBuilder


Chapter

The JBuilder environment


Chapter4
4
This chapter introduces you to the JBuilder integrated development
environment (IDE). To take an introductory tour of JBuilder, open the
Welcome Project. Choose Help|Welcome Project from the JBuilder main
menu.
From the Welcome Project, you can view “Release Notes” by clicking the
Release Notes link. Or you can see “Release Notes” at any time by
choosing Help|Release Notes.
This chapter discusses the following topics:
Available features vary by • Working in the AppBrowser—Explains the JBuilder IDE and the
JBuilder edition. various components of the AppBrowser.
• Working in the editor—Describes JBuilder's many editor features.
• Coding shortcuts—Explains the time-saving coding shortcuts available
in the editor, such as CodeInsight, Find Definition, Optimize Imports,
and code templates.
• Customizing the editor—Provides information on how to customize
and use various editor features. Explains how to customize the editor
display, keybinding, syntax highlighting colors, CodeInsight, code
templates, and other aspects of the editor.
• Customizing JBuilder's IDE—Describes how to customize the JBuilder
IDE. Explains how to customize the AppBrowser, add file types for
JBuilder to recognize, set options for running and debugging, configure
audio options, and configure web, XML, UML, and EJB Designer
options for the IDE.

The JBuilder environment 4-1


Working in the AppBrowser

Working in the AppBrowser


JBuilder uses one window to perform most of the development functions:
editing, visual designing, navigating, browsing, compiling, debugging,
and other operations. This window is called the AppBrowser, and it
contains several panes for performing these development functions. The
tabbed panes that are available in the content pane depend on what kind
of file you have selected in the project pane.
Figure 4.1 The AppBrowser window

You can open multiple AppBrowsers by selecting Window|New Browser


and switch between them by selecting the AppBrowser from the Window
menu. In JBuilder SE and Enterprise, you can also right-click a file in the
project pane and choose Open In New Browser.

4-2 Introducing JBuilder


Working in the AppBrowser

Each instance of the AppBrowser displays the same opened projects;


however, you can open different files in the content pane of each one. All
instances of the AppBrowser are synchronized, so if you have the same
file opened in both, changes to that file in one instance of the AppBrowser
are also made to it in the other instance of the AppBrowser.
Use the View menu to determine which panes show in the current
AppBrowser.

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:

Table 4.1 Toolbar buttons


Icon Menu equivalent Description
File|New Opens the object gallery where you can select from a
variety of wizards.
File|Open Opens a project, file, or package.

File|Reopen Reopens a project, file, or package. Select from a


history list.
File|Close Closes the current file.

File|Save File Saves the current file.

The JBuilder environment 4-3


Working in the AppBrowser

Table 4.1 Toolbar buttons (continued)


Icon Menu equivalent Description
File|Save All Saves all open projects and files, using the current
names.
File|Print Prints selected file or text.

Edit|Undo In the editor, reinserts any characters you deleted,


deletes any characters you inserted, replaces any
characters you overwrite, or moves your cursor back
to its prior position. Undoes actions in the designers.
There are multiple levels of undo.
Edit|Redo Reverses the effects of an Undo.There are multiple
levels of redo.
Edit|Copy Copies selected text in the editor or selected objects
in the UI designer to the clipboard.
Edit|Paste Pastes the contents of the clipboard to the location of
the cursor.
Edit|Cut Cuts selected text in the editor or selected objects in
the UI designer to the clipboard.
Search|Find Searches for text within the currently active file.
Type all lowercase for a case-insensitive search, or
use one or more uppercase letters for a case-sensitive
search. Select previously used searches from the
drop-down menu.
Search|Search Finds the next occurrence of a search string in the
Again currently active file.
Search|Replace Replaces specified text with other specified text in
the active file.
Search|Find Loads the specified class into the AppBrowser. The
Classes class must be on the import path of the active file.
Project|Make Compiles archives, resources, and any .java files
within the selected project that have outdated or
nonexistent .class files. Also compiles any imported
files that the project depends on and which have
outdated or nonexistent .class files.
The arrow provides a drop-down menu allowing
you to choose Make (the default), Rebuild, or a
user-defined build target.
View|Messages Toggles the visibility of the message pane.

Run|Run Project Runs your application using the default


configuration specified on the Run page of the
Project Properties dialog box.
Click the arrow to select a different configuration
from the drop-down list.

4-4 Introducing JBuilder


Working in the AppBrowser

Table 4.1 Toolbar buttons (continued)


Icon Menu equivalent Description
Run|Debug Debugs your program using the default runtime
Project configuration selected on the Run page of the Project
Properties dialog box.
Click the New or Edit button to add or change a
configuration.
Run|Optimize Evaluates the project's code using Optimizeit. This is
Project only available when you have Optimizeit installed.
Search|History Returns you to the starting class or page in the
history list.
Click the arrow to the right of the button to access
the history list.
Search|Back Takes you back to the previous item in the history
list.
Search|Forward Takes you forward to the next item in the history
list.
Help|Help topics Opens the help viewer.

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.

The JBuilder environment 4-5


Working in the AppBrowser

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.

4-6 Introducing JBuilder


Working in the AppBrowser

Package filtering, supported in JBuilder SE and Enterprise, allows you to


exclude packages and subpackages from local builds according to rules
you select. Once you filter a package, a new node containing the excluded
packages appears in the project pane.
You can search for a particular file or package in the project pane by
moving focus to the project tree and beginning to type.

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.

Setting project properties


Use the Project Properties dialog box to set the properties for the active
project. To open it, choose Project|Project Properties.

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.

The JBuilder environment 4-7


Working in the AppBrowser

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

Default project properties


Default project settings are stored in a project called Default.jpx located in
the <.jbuilder> subdirectory of your home directory. This file is used as a
template for new projects. To view or change the default project
properties, choose Project|Default Project Properties from the main menu
and use the Default Project Properties dialog box.

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.

Viewing Javadoc information


These are features of Javadoc @todo tags in Javadoc comments also display in the structure pane
JBuilder SE and in a To Do folder. Javadoc conflicts are displayed in a Javadoc Conflicts
Enterprise. folder.

See also
• “Using @todo tags in the editor” on page 4-25
• “Conflicts in Javadoc comments” in Building Applications with JBuilder

Sorting in the structure pane


You can change the sorting order of the structure pane in the Structure
View Properties dialog box as well as the parse delay. Right-click the
structure pane and choose Properties to open this dialog box and modify
the options.

4-8 Introducing JBuilder


Working in the AppBrowser

Figure 4.3 Structure View Properties

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.

Navigating in the source code


In addition to viewing the structure of the class, the structure pane is a
quick way to navigate to a class, method, or member in the source code.

The JBuilder environment 4-9


Working in the AppBrowser

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.

Viewing error messages


Syntax errors are underlined in the editor. Put your cursor in the error to
see a tooltip that indicates the nature of the error. The tooltip contains one
of two buttons:
• Magnifying glass button: click this to open ClassInsight.
• Question mark button: click this to open the Compiler error message
help file.
Messages about syntax errors are displayed in an Errors folder in the
structure pane. Expand the folder and select an error message. The
pertinent line of code is highlighted in the editor.

See also
• “About error and warning messages” in Building Applications with
JBuilder.

4-10 Introducing JBuilder


Working in the AppBrowser

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.

File view tabs


The tabs that appear at the bottom of the content pane depend on what
kind of file you have open. Only tabs appropriate to the open file appear
below its window. Each of these tabs provides a different view of the open
file. For example, a visually designable .java file would have several tabs:

The JBuilder environment 4-11


Working in the AppBrowser

Source, Design, Bean, UML, Doc, and History. The tabs available vary by
JBuilder edition.

Table 4.2 File view tabs


Tab name Description
Source The Source tab displays the source code of the open file in
the editor.
Design The Design tab displays available designers for the open
file. The designer opens in the default UI designer where
you can see how the code displays in the user interface,
manipulate layouts, create components, modify layout
properties. Several other designers are also available
depending on the JBuilder edition: menu designer and
column designer. Other components, such as pop-up UI
elements or other non-UI JavaBean components, can also be
modified in the designer using the Inspector and the
component palette.
Bean The Bean tab exposes the BeansExpress property, event,
BeanInfo, and property editor designers. Use them to add
properties and events to your bean, choose what properties
are exposed, and create custom property editors. The Bean
tab is read-only in JBuilder Personal.
UML The UML tab displays a UML diagram for a class or
package. This is a feature of JBuilder Enterprise.
Doc The Doc tab shows the API reference documentation for the
class that is opened in the content pane.
History The History tab displays information that helps you
manage revisions of files. It displays the source code of the
active file and a revision list of previous versions of the file.
The features of the history pane vary by JBuilder edition.
View The View tab displays the opened HTML, XML, or image
file in a browser or image viewer in the content pane. To
view XML files, the Enable Browser View option must be
enabled on the XML page of the IDE Options dialog box
(Tools|IDE Options|XML). Viewing XML files is a feature
of JBuilder SE and Enterprise.
Web View The Web View tab displays the output from your running
web file, such as JSPs, servlets, SHTML, and HTML. For
JSPs, the Web View tab displays the output from your
running JSP. For servlets, this tab displays the output from
the running servlet in parsed HTML. This is a feature of
JBuilder Enterprise.
Web View Source The Web View Source tab displays raw HTML in the
content pane. This is a feature of JBuilder Enterprise.
WebApp DD Editor Displays an editor for the web.xml deployment descriptor file
of a WebApp. This is a feature of JBuilder Enterprise.
Transform View The Transform View tab displays a browser view of the
transformed XML document with an XSL stylesheet
applied. This is a feature of JBuilder Enterprise.

4-12 Introducing JBuilder


Working in the AppBrowser

Table 4.2 File view tabs (continued)


Tab name Description
Transform View The Transform View Source tab displays the source code of
Source the transformed XML document. This is a feature of
JBuilder Enterprise.
EJB Designer The EJB Designer tab displays the EJB Designer, which you
use to create EJB 2.0 components. This is a feature of
JBuilder Enterprise.
EJB DD Source The EJB DD Source tab displays the source code of the
deployment descriptors JBuilder creates for you as you
build your enterprise beans. This is a feature of JBuilder
Enterprise.
EJB DD Editor The EJB DD Editor tab displays the Deployment Descriptor
editor. You use the Deployment Descriptor editor to make
changes to an EJB's deployment descriptors. This is a
feature of JBuilder Enterprise.

Resizing the content pane


You can resize the content pane in either of the following ways:
• Drag the splitter bar between the project pane and the content pane to
the size you want.
• Choose View|Hide All from the main menu, or press Ctrl+Alt+Z if using
the CUA key bindings, to expand the content pane fully and to hide all
the other panes.

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.

The JBuilder environment 4-13


Working in the AppBrowser

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.

4-14 Introducing JBuilder


Working in the AppBrowser

• A status bar next to the toolbar which indicates state of debugging


processes.
If the debugger does not appear after you choose Run|Debug, set a
breakpoint on an executable statement by clicking the left gray margin of
the editor and choose Run|Debug again.
The toolbar at the bottom of the debugger provides quick access to Reset,
Resume, and Pause buttons, as well as Smart Step, Step Over, Step Into,
Step Out, Add Breakpoints, Add Watch, and Show Current Frame
buttons.

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.

The JBuilder environment 4-15


Working in the AppBrowser

Navigating and searching in the AppBrowser


Navigation shortcuts
Use the following keyboard shortcuts to navigate in the AppBrowser
panes.

Table 4.3 Navigation keyboard shortcuts


Keyboard
shortcut Action
Ctrl+Tab Moves forward in rotation order to the next AppBrowser pane.
The rotation order is project pane, content pane, message tab,
message pane text area, and structure pane.
Shift+Ctrl+Tab Moves backwards in reverse rotation order to the previous
AppBrowser pane.
Up/down arrow keys Moves the selection cursor up and down in a tree.
Left/right arrow keys Project and structure pane—expands and collapses top level tree
node branches.
Enter Project pane—opens a selected source file. This is equivalent to a
double-click.
Structure pane—drills down into the superclass or interface of
the selected class. This is equivalent to a double-click.

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.

4-16 Introducing JBuilder


Working in the AppBrowser

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:

1 Select the class you want to open.


2 Click OK or press Enter.
The dialog closes and the class opens and becomes the active file in the
editor.
Both pages support the wildcards * and ?.

The JBuilder environment 4-17


Working in the editor

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.

Working in the editor


To access the JBuilder editor, open a text-based file and click the Source
tab in the content pane. To open a file in the content pane, either
double-click it in the project pane (upper left pane) or select it and press
Enter. Note the file status bar at the bottom of the editor, indicating the file
name, the cursor location (line number and column), and the insertion
mode of a text-based file or the size of an image file.
The editor offers a variety of productivity features, such as brace
matching, keyboard shortcuts, syntax highlighting, customizable editor

4-18 Introducing JBuilder


Working in the editor

keymappings, CodeInsight, code templates, searching, and printing, as


well as a fully customizable editor. Many of these features can be set in the
Editor Options dialog box (Tools|Editor Options).
Many more features are available from the editor's context menu. These
vary depending on which JBuilder edition you're using, what your project
settings are, and where the cursor is in the editor when you invoke the
menu. Right-click with your cursor in the editor to invoke the context
menu.

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.

The JBuilder environment 4-19


Working in the editor

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.

4-20 Introducing JBuilder


Working in the editor

Using the editor's context menu


The editor has a context menu for quickly accessing common editor
commands. Right-click in the editor to activate the menu. The commands
on the context menu vary by JBuilder edition and depend on what is
selected. See the following documentation for information on these
commands:
• Split Vertically/Split Horizontally: “Splitting the source view” on
page 4-21
• Find Definition: “Finding a symbol's definition” on page 4-22
• Find References: “Finding references to a symbol” on page 4-23
• Optimize Imports: “Optimize imports” in “Refactoring code symbols”
in Building Applications with JBuilder
• Rename: “Rename refactoring” in “Refactoring code symbols” in
Building Applications with JBuilder
• Move: “Move refactoring” in “Refactoring code symbols” in Building
Applications with JBuilder
• Change Parameters: “Change parameters” in “Refactoring code
symbols” in Building Applications with JBuilder
• Introduce Variable: “Introduce variable” in “Refactoring code
symbols” in Building Applications with JBuilder
• Surround with Try/Catch: “Surround with Try/Catch” in “Refactoring
code symbols” in Building Applications with JBuilder
• Toggle Breakpoint/Enable Breakpoint/Breakpoint Properties:
“Debugging Java programs” in Building Applications with JBuilder
• Editor Options: Editor Options dialog box (Tools|Editor Options)
Note Editor commands are also available from the Edit menu.

Splitting the source view


This is a feature of The editor lets you split the source view of a file into two or more vertical
JBuilder SE and or horizontal panes. This setting applies to an individual file, not to all the
Enterprise. opened files in the content pane. You can have a different configuration
for every opened file.
To split the view, right-click and choose either Split Vertically or Split
Horizontally. Note that many other menu items are also available from
this context menu. To return a split view to one pane, right-click in each
pane and choose Close View.

The JBuilder environment 4-21


Working in the editor

Finding text in the editor


The editor provides numerous ways to find and replace specific text in a
file. Search commands are located on the Search menu as well as from
icons in the main toolbar. Modify search options on the Editor page of the
Editor Options dialog box (Tools|Editor Options|Editor).

Table 4.4 Commands for finding text


Task Command
Find text Search|Find
Search for text across all files in the selected path(s) Search|Find in Path
Find text and replace it with new string Search|Replace
Search for the same text again Search|Search Again
Search for text incrementally, as you type in the Search|Incremental Search
search string
Go to a specific line number Search|Go To Line
Browse through a class, interface, or package Search|Find Classes
Find the declaration of a variable, method, class, or Search|Find Definition
interface
Find uses or instances of a variable, method, class, or Search|Find References
interface
Navigate to a specific item in the history list Search|History
Navigate to the previous item in the history list Search|Back
Navigate to the next item in the history list Search|Forward
Set bookmarks and return to them Key combinations listed in
the keymap file (Help|
Keyboard Mappings)

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.

Finding a symbol's definition


The Find Definition command, available on the editor's context menu and
from the Search menu, allows you to navigate from the usage of a symbol
to its definition. To use Find Definition,
1 Position the cursor in the editor on the symbol you want to see defined.

4-22 Introducing JBuilder


Working in the editor

2 Right-click and choose Find Definition.


The source file where the symbol is defined is opened in the editor, with
the cursor positioned on the symbol's definition.
Important In order for a definition to be located, you must have already compiled
your project. The class that includes the definition must be on the import
path.

See also
• “Finding a symbol's definition” in “Refactoring code symbols” in
Building Applications with JBuilder.

Finding references to a symbol


This is a feature of The Find References command, available on the editor's context menu and
JBuilder SE and the Search menu, allows you to discover all source files that use a given
Enterprise. symbol. To use Find References,
1 Position the cursor in the editor on the symbol you want to find all
references to.
2 Right-click and choose Find References.
The references found are sorted by category and displayed on the
Search Results tab of the message pane.
To discover the source file(s) where the reference exists, expand a category
node and traverse the hierarchy tree. Double-click a reference in order to
open the source file and to position the cursor directly on the reference in
the file.
Important In order for a reference to be located, you must have already compiled
your project. For more information, see “Setting up for references
discovery and refactoring” 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.

Javadoc shortcuts in the editor


Javadoc is a Sun Microsystems utility that generates HTML
documentation files from comments you enter in API source files. The
comments must be formatted according to Javadoc standards. Use
JBuilder's Javadoc wizard (Wizards|Javadoc wizard) to set up properties

The JBuilder environment 4-23


Working in the editor

for generating Javadoc (JBuilder SE and Enterprise). Then, when you


build your project, Javadoc is automatically generated.
To make coding Javadoc comments easy, the JBuilder editor contains a
Javadoc comment template, activated when you type /**. The template
automatically adds the Javadoc end comment symbol, */. If the cursor is
positioned immediately before a class, interface or method signature the
template expands to include appropriate Javadoc tags (JBuilder SE and
Enterprise.).
To quickly add a Javadoc comment block,
• Position the cursor at the desired indentation level before a class,
interface, or method signature.
• Type /**.
• Press Enter.
In JBuilder SE and Enterprise, the editor automatically adds the Javadoc
end comment symbol and positions the cursor in the second line of the
comment. If necessary, it adds appropriate tags.
For example, entering /** before the import statements in a class source
file generates the following comment block:
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2001</p>
* <p>Company: </p>
* @author
* @version 1.0
*/
In JBuilder Personal, the editor automatically adds the Javadoc end
comment symbol and positions the cursor in the second line of the
comment.
In JBuilder SE and Enterprise, entering /** for the following method
signature:
public void addValues(Double valueOneDouble, Double valueTwoDouble)
creates the following Javadoc comment:
/**
*
* @param valueOneDouble
* @param valueTwoDouble
*/
For more information on JBuilder and Javadoc, see “Creating Javadoc
from API source files” in Building Applications with JBuilder.

4-24 Introducing JBuilder


Working in the editor

Using @todo tags in the editor


Javadoc @todo tags are useful for adding reminders about what needs to be
done to an area of code. These tags are placed inside of Javadoc
comments.
This is a feature of These @todo tags appear in JBuilder's structure pane in a To Do folder.
JBuilder SE and
JBuilder's code templates make adding @todo tags to your code very easy.
Enterprise.
1 Type todo at the appropriate indentation level in the editor.
2 Press Ctrl+J to expand the template in your code:
/** @todo <cursor placed here> */
Some of JBuilder's wizards generate @todo tags as reminders to add code to
the stub code that the wizard generates.

Printing support in the editor


You can use the File|Print command to print your source code directly
from the editor.
The File|Page Layout command displays the Page Layout dialog box,
where you can set layout options:
• Page Layout: The options on the Page Layout page let you choose the
page orientation, layout, and font, and configure line numbering and
wrapping.
• Advanced: The options on the Advanced page let you set margins and
print page headers. Use the following variables to control what is
printed in the page header.

Table 4.5 Page header variables


Variable Description
%f Filename and path
%g Filename only
%p Page number
%n Total page count
%t Time
%d date (long version)
%s date (short version)
%u Username

The JBuilder environment 4-25


Coding shortcuts

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.

4-26 Introducing JBuilder


Coding shortcuts

Figure 4.5 CodeInsight pop-up window

To access CodeInsight, use these keyboard shortcuts.

Table 4.6 CodeInsight shortcut keystrokes


Pop-up window Keystrokes Actions
MemberInsight Ctrl+H Provides methods and members of active
scope.
ParameterInsight Ctrl+Shift+H Provides method parameters.
Find Definition Ctrl+Enter Drills down to the definition of a symbol.
(Drill Down)
ClassInsight Ctrl+Alt+Space Inserts a class name into a writable file.
Ctrl+Alt+H JBuilder Enterprise provides insertion
style options.
Code templates Ctrl+J Provides code templates.

Note For Macintosh, use the Command key in place of Ctrl.


These keystrokes are the JBuilder defaults. To view the current list of
keystrokes for any keymap, see the Keymap Editor dialog box. To open
the Keymap Editor, choose Tools|Editor Options, choose the keymap you
want to see, and press the Customize button on the Editor page. In
JBuilder SE and Enterprise, the keystrokes can be configured using this
dialog box.
Tip If CodeInsight fails, look for such errors as missing braces or missing
import statements.
Use arrow keys to move the selection up and down the list. To accept a
CodeInsight selection, press Enter, any non-alphanumeric character
([, =, \, etc.), or the space bar.

The JBuilder environment 4-27


Coding shortcuts

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.

4-28 Introducing JBuilder


Coding shortcuts

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

The JBuilder environment 4-29


Coding shortcuts

name and press Ctrl+Shift+Space, Ctrl+Shift+H, or the left parenthesis character


((). All possible parameters are displayed, including overloaded ones.
If the source code of the method is available, the parameter names are
shown. As you fill in the parameters for the method call, the current
parameter is highlighted in the parameter list.

Find Definition (Drill Down)


Find Definition quickly takes you to the source code for the current
variable, method, or class name in the editor if it exists. If it's not available,
it takes you to the stub source. To invoke this feature, place the cursor on
the symbol in your source code and press Ctrl+Enter. See Help|Keyboard
Mappings for a complete list of keystrokes by keybinding.

Tool tip expression evaluation


This is a feature of When you are debugging a program, you can place the mouse cursor over
JBuilder SE and any variable in the editor to display its value. The value is displayed in a
Enterprise. small pop-up panel that looks like a tool tip.

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.

4-30 Introducing JBuilder


Coding shortcuts

To use a code template in your code, select one of these methods:


• Type the code template name, such as classp, in your code where you
want the code to appear and press Ctrl+J. See Tools|Editor Options|
Templates for the template names.
• Position the cursor where you want the code to appear and press Ctrl+J
to display a list of code templates. Select from the list using the arrow
keys and press enter.
The editor automatically expands the template.
Tip Once you've expanded the template, use CodeInsight to assist you in
writing your code. See “Coding shortcuts” on page 4-26.
JBuilder's pre-defined code templates are formatted according to your
project preferences. These options are set in the following locations:
• Braces option: Project|Project Properties|Code Style page
• Block Indent option: Tools|Editor Options|Editor page

Editing code templates


This is a feature of You can edit JBuilder's default templates, create new ones, or delete any
JBuilder SE and you don't need. To edit this list, right-click in the editor, select Editor
Enterprise. Options, and click the Templates tab.
To create a new code template,
1 Choose Tools|Editor Options and click the Templates tab.
2 Press the Add button on the Templates page.
3 Enter the name and description of the new code template, then press
OK.
4 Type the code for the new template in the Code text editing area.
5 Add or edit other templates, then press OK when you are finished to
close the Editor Options dialog box.
To edit an existing code template,
1 Choose Tools|Editor Options and click the Templates tab.
2 Use the mouse or the Up/Down arrow keys in the code template list to
select the one you want to edit.
3 Press the Edit button on the Templates page to change the name or
description of the selected template.
4 Enter the name and description of the new code template, then press OK.
5 Type in the Code text editing area to modify the code sample.
6 Add or edit other templates, then press OK when you are finished to
close the Editor Options dialog box.

The JBuilder environment 4-31


Customizing the editor

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.

Customizing the editor


Use the Editor Options dialog box to customize the editing environment
in JBuilder. To open this dialog box, choose Tools|Editor Options from
the main menu or right-click in the source pane and select Editor Options.
The Editor Options dialog box contains the following pages:
• Editor
• Display
• Color
• CodeInsight
• Templates
• Java Structure
Note To return to the settings that were in effect when you brought up the
dialog box, click the Reset button on the appropriate page.

See also
• “Customizing JBuilder's IDE” on page 4-45

4-32 Introducing JBuilder


Customizing the editor

Customizing editor behavior


Use the Editor page of the Editor Options dialog box to customize editing
behavior.

Customization features on the Editor page include:


• Keymap
Sets the keymapping definitions for the editor. The default is the CUA
keymappings. For a complete listing of editor keymapping definitions,
see “Keyboard mappings” available on the Help menu.
• Customize
Displays the Keymap Editor dialog box for the selected editor where
you can customize your keymapping for the selected keymap. The
Keymap Editor is read-only in JBuilder Personal.
• Block Indent
Specifies the number of characters between indent levels in text. This is
the effective 'tab stop' level for everything except actual tab characters.
The value is used for indenting marked blocks and for indenting when
the Tab key is pressed. The default is 2 spaces; the upper limit is 20.
• Tab size
Sets the number of characters between tab stops for actual tab
characters. This option is only used for displaying text already
containing tab characters. Pressing the Tab key may indent by a
different amount. See Block Indent above. The default setting is 8.

The JBuilder environment 4-33


Customizing the editor

• 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

4-34 Introducing JBuilder


Customizing the editor

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.

The JBuilder environment 4-35


Customizing the editor

• Enable Brace Match Highlighting highlights both braces in a set


when the cursor is immediately to the right of one. Default is on.
Change the color and style of highlighting in the Color page of this
dialog box.
• Highlight Opposing Brace Only highlights the brace that matches
the selected brace. Default is off.
• Ignore Neighboring Braces prevents braces from being highlighted
when there are no characters between them, as in an empty array or
a method with no args.
Note Unless otherwise specified, the term “brace” here includes curly braces,
parentheses, and square brackets.
• Error Options
Specifies how syntax errors are marked and provides assistance in
handling them.
• Underline Errors underlines syntax errors with squigglies. Default
underline color is red. Change the color in the Color page of this
dialog box.
• Show Tooltip displays a tooltip specifying the nature of the syntax
error. Default is on. The tooltip contains one of two buttons:
• Magnifying glass button: click this to open ClassInsight.
• Question mark button: click this to open the Compiler error
message help file.
• Show In Gutter displays an error icon in the gutter next to a syntax
error. Default is off.

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.

4-36 Introducing JBuilder


Customizing the editor

• 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.

The JBuilder environment 4-37


Customizing the editor

The options on the Color page set the following:


• Editor Color Scheme
Quickly configures the editor display using predefined color
combinations.
• Screen Element
Specifies syntax highlighting for a particular element. You can choose
from the Screen Element list or click the element in the sample box.
• Attributes
Specifies format attributes for the code element selected in the Screen
Element list.
• Foreground
Sets the foreground color for the selected code element. To set the color,
choose a color from the Foreground palette. The selected color is
displayed above the Foreground palette. To create a custom color,
right-click the palette to the right of the standard palette. Choose Use
Default to restore the selected code element to its default foreground
system color.
• Background
Sets the background color for the selected code element. To set the
color, choose a color from the palette. The selected color is displayed
above the Background palette. To create a custom color, right-click the
palette to the right of the standard palette. Choose Use Default to
restore the selected code element to its default background system
color.
• Sample code
Displays selected settings in a code snippet.

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.

4-38 Introducing JBuilder


Customizing the editor

To open the CodeInsight page, choose Tools|Editor Options, then click


the CodeInsight tab. You can also right-click in the editor and select Editor
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.

The JBuilder environment 4-39


Customizing the editor

• Auto Complete While Typing


When this option is selected, the code is completed for you
automatically as soon as a match is reached. This feature is off by
default. If the Auto Pop-up MemberInsight option is off, this option is
also off.
• Include Classes
Displays class names in the MemberInsight window. The default is on.
• Include Deprecated Members
Determines whether deprecated methods appear in the list. The default
is on.
• Show Class Context
Displays class name at the top of the pop-up window. 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.

Display Options button


Display Options controls the settings for CodeInsight features, including
color, font, and font size. To customize the CodeInsight display, press the
Display Options button on the Editor Options|CodeInsight page to open
the CodeInsight Display Options dialog box.

4-40 Introducing JBuilder


Customizing the editor

MemberInsight page
The MemberInsight page configures how CodeInsight displays the list of
accessible methods and data members for the current context.

The MemberInsight page has the following settings:


• Show Entry Types As Icons
Displays the type of accessible data member as an icon. The default is
on.
• Use Strike-through For Deprecated Members
Strikes through data members or methods that have been deprecated.
Note that deprecated members appear only if the Show Deprecated
Members 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 entries in the MemberInsight window.
• Size
The text point size.
• Foreground
The color of the text.
• Background
The color of the background.

The JBuilder environment 4-41


Customizing the editor

• 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.

4-42 Introducing JBuilder


Customizing the editor

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.

The JBuilder environment 4-43


Customizing the editor

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.

4-44 Introducing JBuilder


Customizing JBuilder's IDE

• Separate Classes/Methods/Fields: Classes appear first in the


structure pane, followed by methods, which are followed by the
fields of the Java source. The default is on.
• Sort Alphabetically: Sorts the structure elements in alphabetical
order. The default is on.

Customizing JBuilder's IDE


Use the IDE Options dialog box to customize the JBuilder IDE (integrated
development environment). To open this dialog box, choose Tools|IDE
Options from the main menu.
The IDE Options dialog box contains the following pages, which vary by
JBuilder edition:
• Browser
• File Types
• Web
• XML
• Run/Debug
• Audio
• UML
• EJB Designer
Note To return to the settings that were in effect when you brought up the
dialog box, click the Reset button.
For information on modifying the editing environment, see “Customizing
the editor” on page 4-32.

The JBuilder environment 4-45


Customizing JBuilder's IDE

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.

4-46 Introducing JBuilder


Customizing JBuilder's IDE

• Content Pane Tabs


You can alter the orientation, label type, and insertion of the tabs in the
content pane. Select from these options:
• Orientation
• Horizontal: places the tabs horizontally on the top of the content
pane
• Vertical: places the tabs vertically on the right side of the content
pane
• Label Type
• Icon And Short Name
• Name: file name with the extension
• Short Name: file name without the extension
• Icon Only
• Insertions
The Insertions selection controls where new tabs are added in the
content pane. The default for Tab Insertions is Sort Alphabetically.
Choose from the following options.
• Sort Alphabetically: positions tabs in alphabetical order.
• Sort Display Order: sorts the same way as the project pane. For
example, tabs for package nodes and other lightweight nodes sort
to the beginning of the tab control.
• Insert At Beginning: inserts a new file as the first tab.
• Insert To Left Of Tab For Active Node: inserts a new file to the left
of the currently selected tab.
• Insert To Right Of Tab For Active Node: inserts a new file to the
right of the currently selected tab.
• Insert At End: inserts a new file as the last tab.
• Error Text Color
Sets the color for non-warning compiler error messages, error
conditions, and on the Methods tab within BeansExpress. Choose the
drop-down arrow to open the palette. Select from the standard colors
or right-click the empty palette to the right of the standard colors to
create a custom color.

The JBuilder environment 4-47


Customizing JBuilder's IDE

File Types options


Use the File Types page of the IDE Options dialog box to customize the
types of files the JBuilder editor recognizes. To open the File Types page,
choose Tools|IDE Options, then click the File Types tab.

The File Types page controls the following:


• Recognized File Types
The list of file types that the JBuilder editor recognizes. When a file type
is recognized, the JBuilder editor will open it.
• Associated Extensions
The file extensions associated with the type of file selected in the
Recognized File Types list.
• Add
Displays the Input dialog box, where you add a file extension to the list
of Associated Extensions for the selected type of file. Note that this does
not add types of files to the Recognized File Type list.
• Remove
Removes the selected file type from the list.

4-48 Introducing JBuilder


Customizing JBuilder's IDE

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.

The Web options include:


• Copy Web Run/Debug Launch URL To Clipboard
Copies the URL used to launch the web application to the clipboard.
This will enable you to easily go to the same URL in an external
browser.
• Launch Separate Process And Use Web View
Automatically displays your rendered servlet or JSP in the Web View
page of the content pane and in an external web browser.
• Use Web View On Running Process If Possible
Automatically displays your rendered servlet or JSP in the internal
browser, the Web View page of the content pane. If a web server is
already running, JBuilder will use the same process on the existing
port. This is the default.
• Do Not Use Web View, Always Launch Separate Process
Always launches your web application in an external web browser.

The JBuilder environment 4-49


Customizing JBuilder's IDE

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.

The XML options include:


• Enable Browser View
When this option is set, you can view the XML document on the View
tab of the content pane.
• Apply Default Stylesheet
Applies JBuilder's default XSLT stylesheet, a tree view, to the XML
document.
• Transform Trace Options
Transform trace options allow you to view the flow of transformation
in a document. Choose from Trace Selections, Trace Templates, Trace
Generation, Trace Elements. Traces display in the message pane in a
tree view. Choose a trace to highlight the corresponding source line and
double-click to change the cursor's focus to the editor.

4-50 Introducing JBuilder


Customizing JBuilder's IDE

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.

The Run/Debug page controls the following:


• Runtime Update Intervals
Sets the duration of runtime updates to the console.
• Debugger Update Intervals
Sets the duration of debug updates to the console.

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

The JBuilder environment 4-51


Customizing JBuilder's IDE

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

4-52 Introducing JBuilder


Customizing JBuilder's IDE

3 Archive the files into a compressed or uncompressed ZIP archive.


4 Name the archived file with an .audiopak extension.
5 Save the archive to the lib/audio/ directory of the JBuilder installation.
6 Restart JBuilder if it is currently running for the new theme to be visible
in the drop-down list.
Note .wav files must have 16-bit sampling.

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.

The JBuilder environment 4-53


Customizing JBuilder's IDE

• Use Visibility Icons


Displays icons in the UML diagram. These are the same icons that
display in the structure pane when a source file is open in the editor.
For definitions of these icons, see “Structure pane and UML icons” in
the Help index under “icons.” When this option is off, the standard
UML visibility icons are used. See “Visibility icons” in “Visualizing
code with UML” in Building Applications with JBuilder.
• Group By Visibility
Groups class methods and data members from the most visible to the
least visible; therefore, public methods and data members are followed
by protected, which are followed by private.
• Sort Alphabetically
Sorts class methods and data members alphabetically in the UML
diagram.
• Display Properties Separately
Displays any class variables with getters and/or setters separately in
the UML diagram.
• Font Family
Select a font type from the list of available screen fonts installed on your
system.
• Font Size
Select a font size for the UML diagram from the predefined font sizes
associated with the font you selected in the Font Family list box.
• Screen Element
Choose a UML element in the Screen Element list and select a new color
to change the default color displayed in the UML viewer. 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.

4-54 Introducing JBuilder


Customizing JBuilder's IDE

EJB Designer options


This is a feature of Use the EJB Designer page of the IDE Options dialog box to globally
JBuilder Enterprise. configure the display of the EJB Designer. You can control such options as
font, font size, and color of text, borders, and backgrounds. To open the
EJB Designer page, choose Tools|IDE Options, and choose the EJB
Designer 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.

The JBuilder environment 4-55


4-56 Introducing JBuilder
Chapter

Automating code development


Chapter5
5
JBuilder provides a variety of tools for fast application development:
visual design tools for quickly creating UIs and wizards for automatically
generating code. The visual design tools include a UI designer, a menu
designer, and a column designer and are accessible on the Design tab of
the content pane. Many of the wizards are available from the object
gallery (File|New) and from the Wizards menu.

Working with the visual design tools


The JBuilder visual design tools consist of a component palette, an
Inspector, several designers, and a component tree. To access the design
tools, you must open a source file in the content pane, then click the
Design tab.

Automating code development 5-1


Working with the visual design tools

Figure 5.1 JBuilder in design view

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

5-2 Introducing JBuilder


Using the object gallery

• “Tutorial: Creating a calculated column in the designer” in the Database


Application Developer’s Guide
• “Restructuring JDataStore StorageDataSets” in the JDataStore
Developer’s Guide

Using the object gallery


The object gallery gives you access to wizards you can use to create
skeletal instances of many objects.
To use a wizard in the object gallery, choose File|New to open the object
gallery. Select a wizard icon then click OK. JBuilder opens the associated
wizard and creates the skeletal code in an appropriate file which it adds to
your project.
Wizards that are grayed out in the object gallery are disabled. Some
wizards only become enabled after creating or opening a project or a
specific type of file. Also, wizards can be disabled if they are not available
in a JBuilder edition. Wizards vary by JBuilder edition.
Important Some wizards, such as those on the CORBA and Enterprise pages, require
registration or special setup before they are enabled.

Using wizards to get a quick start


JBuilder wizards save you time by automatically generating code for you.
You can access these wizards from several menus:
• File|New menu which opens the object gallery
• Wizards menu
• Tools menu

Automating code development 5-3


5-4 Introducing JBuilder
Chapter

Creating and managing projects


Chapter6
6
JBuilder does everything within the context of a project. As used in this
documentation, the term “project” includes all the files within a user-
defined body of work, the directory structure those files reside in, and the
paths, settings, and resources required.
The project is an organizational tool, not a repository. This means that files
in a project can be in any folder. Restructuring a project tree has no effect
on your directory tree. This gives you independent control of projects and
directory structure.
Each project is administered by a project file. The project file's name is the
name of the project with a JPX extension. The project file contains a list of
files in the project and maintains the project properties, which include a
project template, default paths, class libraries, and connection
configurations. JBuilder uses this information when you load, save, build,
or run a project. Project files are modified whenever you use the JBuilder
development environment to add or remove files or set or change project
properties. You can see the project file as a node in the project pane. Listed
below it are all the packages and files in the project.
Note If automatic source packaging is enabled, source package nodes also
appear in the project pane. These display files and packages that are on
the project's source path. See “Automatic source packages” in Building
Applications with JBuilder.
While you can include any type of file in a JBuilder project, there are
certain types of files that JBuilder automatically recognizes and for which
it has appropriate views.
This is a feature of You can add binary file types, customize file type handling, and see the
JBuilder SE and icons associated with file types by selecting Tools|IDE Options and
Enterprise. choosing the File Types tab.

Creating and managing projects 6-1


Creating a new project

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.

Creating a new project


To start a new project, use JBuilder's Project wizard to generate the basic
framework of files, directories, paths, and preferences automatically. The
Project wizard can automatically create a project notes file for your notes
and comments. The class Javadoc fields that are filled out in the Project
wizard are used in the project notes file, as Javadoc header comments
when using JBuilder's wizards to create Java files, and consequently
included in Javadoc-generated documentation. These comments can be
modified on the General page of the Project Properties.
When using many of JBuilder's wizards, if a project is not open, the Project
wizard is launched first so that you can create a new project.

Creating a new project with the Project wizard


The Project wizard sets up the default settings for a new project. To import
an existing project, use the Project For Existing Code wizard, a feature of
JBuilder SE and Enterprise. See “Creating a project from existing files” on
page 6-8.
Warning The Project wizard is designed to create new projects, not to import
existing ones. If you attempt to use it to import existing projects, please be
aware that your existing project's structure may be problematic in
JBuilder.
To create a new project with the Project wizard, select File|New Project.
You may also choose File|New, select the Project tab, and double-click the
Project icon. The Project wizard appears.

Step 1: Selecting project name and template


Step 1 sets your project name, type, root directory, and project template.
The project template provides default values for the settings described in
the Project|Project Properties dialog. If you already have a project whose
project properties are close to what will be required in the new project,

6-2 Introducing JBuilder


Creating a new project

select it here. This minimizes the repetitive work involved in setting up a


new project within an established environment.

1 Enter a name for the new project.


JBuilder uses the project name as the package name by default.
Any file name legal to the file system is allowed for the project name.
However, there are other names which are derived from this file name
and these derived names have restrictions which must be met:
• The project directory name can appear on a Java classpath. Since
embedded spaces can cause problems, if there are spaces, they are
replaced with underbars.
• The wizard uses the project name as the default package name.
Therefore, it must be a legal Java package name. This means that
leading numbers are removed from the file name, spaces are
replaced with underbars, the case is forced to lowercase, and the
name may have to be truncated if it's too long.
2 Select the project directory. This is the parent directory of the project
file. Many other project paths, such as the source and backup paths,
descend from this by default.
• Click the down arrow to select a directory you've used previously as
the parent or to choose one in the same tree that you can edit.
• You can edit the field directly or click the ellipsis (...) button to
browse to an existing directory.
Note If you enter a path that's syntactically flawed, you can't proceed.
3 Select your project template.
• Click the down arrow to choose a project you've used previously as a
template.

Creating and managing projects 6-3


Creating a new project

• 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.

Step 2: Setting project paths


Step 2 sets all paths for the project, including the JDK version to compile
against. These settings can later be changed on the Paths page of the
Project Properties dialog box (Project|Project Properties).

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.

6-4 Introducing JBuilder


Creating a new project

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.

Creating and managing projects 6-5


Creating a new project

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.

Step 3: Setting general project settings


Step 3 of the Project wizard includes general project settings, such as
encoding, default runtime configuration, automatic source packages, class
Javadoc fields, and references from project libraries.
This information can later be changed on the General page and Run page
of the Project Properties dialog box (Project|Project Properties).

1 Choose an encoding or accept the default encoding. Encoding


determines how JBuilder should handle characters beyond the ASCII
character set. The default is your platform's default encoder.

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

6-6 Introducing JBuilder


Creating a new project

in the assertion facility. assert takes a boolean value which checks a


condition before the associated expression is executed.
Assertions are enabled or disabled at runtime.

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

Creating and managing projects 6-7


Creating a project from existing files

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).

Creating a project from existing files


This is a feature of The Project For Existing Code wizard allows you to create a new JBuilder
JBuilder SE and project using an existing body of work. When you use this wizard,
Enterprise JBuilder scans the existing directory and builds paths that are used for
compiling, searching, debugging, and other processes. Any JAR or ZIP
files that aren't already in libraries are placed in a new library and added
to the project. Project libraries are listed on the Required Libraries tab of
the Paths page of Project Properties (Project|Project Properties).
To access the Project For Existing Code wizard,
1 Select File|New. The object gallery appears.
2 Select the Project tab.
3 Select Project For Existing Code.
Double-click or click OK to activate the wizard.

6-8 Introducing JBuilder


Creating a project from existing files

Step 1: Selecting source directory and name for your new


JBuilder project
Step 1 sets your project directory, name, type, and project template.
1 Choose the directory where the existing project or source tree is located.
Click the ellipsis button to browse to it. JBuilder scans the selected
directory for such files as class, source, JAR, and ZIP and places them in
the appropriate directories within that directory.
2 Enter a name for the new project. JBuilder uses the project name as the
package name by default, so if you have an existing package name use
that as the project name. JBuilder's wizards also use the project name as
the package name, which can be edited in the wizards.
3 Select your project template.
• Click the down arrow to choose a project you've used previously as a
template.
• Click the ellipsis button to use a different project as the template in
the Open Project dialog box.
The project template provides default values for the settings
described in the Project Properties dialog box (Project|Project
Properties). If you already have a JBuilder project whose project
properties are close to what is required in the new project, select it
here. This minimizes the repetitive work involved in setting up a
new project within an established environment.
4 Choose whether to generate an HTML project notes file. The initial
information in this file, such as title, author, and description, is
generated from the class Javadoc fields set in Step 3 of the Project For
Existing Code wizard. You can also add notes and other information in
this file as needed.
5 Click Next to go to Step 2.
Steps 2 and 3 of the Project For Existing Code wizard are identical to the
Project wizard. These steps are also the same as the Paths page and the
General page of Project Properties. See “Creating a new project with the
Project wizard” on page 6-2.
If your project requires specific libraries, you can add them to the project
on the Paths page of the Project Properties dialog box. To set the main
class to run your project, choose the Run page of the Project Properties
dialog box.

See also
• “Setting paths for required libraries” on page 7-10
• “Using the Run command” in Building Applications with JBuilder

Creating and managing projects 6-9


Displaying files

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”

Switching between files


When you have a lot of files open, it doesn't always make sense to look
through all the open file tabs to find the one you want to use. There are
two ways to switch quickly between open files.

6-10 Introducing JBuilder


Saving projects

• Use the Switch dialog.


a Either select Switch from the Window menu or type Ctrl+- (minus
sign or hyphen.)
b Select the file you want to use.
Start typing the name of the file and the first match in the list is
selected.
Scroll up and down the list with the keyboard arrows.
c Click OK or press Enter.
That file becomes the currently active file.
• Choose from the open files listed in the Window menu. The currently
active file has a check next to it.
You can also switch between open projects from the Window menu.

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.

Saving and closing projects


To save a project, select File|Save All, File|Save Project, or click the Save
All button on the main toolbar.
To close a project, select File|Close Projects or click the Close Project
button on the project toolbar.

See also
• “How JBuilder constructs paths” on page 7-14
• “Where are my files?” on page 7-17

Creating and managing projects 6-11


Opening an existing project

Opening an existing project


There is one way to open an existing project for the first time: use File|
Open Project. There are two ways to open an existing project you have
opened before: either the File|Open Project command or the File|Reopen
command.
To open a project using the File|Open Project command,
1 Choose File|Open Project. The Open File dialog box appears.
2 Navigate to the directory that contains the project file you want to
open.
3 Select the project file and click OK or press Enter. You can also double-
click the project file to open it.
To open a previously opened project with the File|Reopen command,
1 Choose File|Reopen.
2 Choose the project you want to open from the list of previously opened
projects.
The project file and its source files will appear in the project pane.
To open a file in the content pane, you may do one of three things:
• Double-click the file in the project pane.
• Select the file in the project pane and press Enter.
• Right-click the file in the project pane and select Open.
To view a project in a new AppBrowser,
1 Select Window|New Browser.
2 Select File|Open Project and navigate to the file in the Open Project
dialog box.
If you have more than one AppBrowser open and the same files open in
multiple AppBrowsers, changes you make in one AppBrowser will be
reflected immediately in the same file open in the other AppBrowser. This
keeps all your working versions of a file congruent.
Note All open projects are available in all AppBrowsers from the Project drop-
down list.

6-12 Introducing JBuilder


Creating a new Java source file

Creating a new Java source file


Use the Open File dialog box to create a single, empty Java file.
There are several ways to create Java source files within JBuilder. Many of
JBuilder's wizards create files. Most of these are available from the object
gallery (File|New) or from the Wizards menu. Specifically, the Class
wizard generates the framework of a new Java class.
To create a new Java source file using File|Open File,
1 Select File|Open File to open the Open File dialog box.
2 Type the name of the file.
3 Choose the .java file type from the drop down list or include the
extension when you type the name.
4 Click OK or press Enter.
5 Click OK at the File Does Not Exist prompt.
6 JBuilder creates the new file and opens it in the content pane.
To create a new Java source file using the Class wizard,
1 Create a new project as described in “Creating a new project” on
page 6-2.
2 Choose File|New Class.
3 Enter the package, class, and base class names in the Class wizard.
4 Select options for exposure, method handling, and header comments.
The .java file is created and added to your project (its node appears in the
project pane). The new file opens in the content pane in editor.

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.

Creating and managing projects 6-13


Managing projects

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.

6-14 Introducing JBuilder


Managing projects

Adding files and packages


Automatic source path discovery, a feature of JBuilder SE and Enterprise,
adds new files and packages to the project on the fly. Set this option on the
General page of the Project Properties dialog. It's on by default.
If you're not using this feature, files and packages must be explicitly
added to a project in order for JBuilder to treat them as part of the project.
Add files and packages to the current project using the Add Files Or
Packages To Project dialog box.
There are two ways to access this dialog box. Use the way you prefer:
• Click the Add Files/Packages button that's on the project pane toolbar.
• Right-click any node in the project pane and choose Add Files/
Packages from the context menu.
Once the dialog box is available:
1 Select:
• The Explorer page to add a file.
• The Packages page to add a package.
Both of these pages support multiple selection.
2 Navigate to the file or package you want to import.
3 Select the file or package you want. Once you're in a file's parent
directory, you may type in the filename instead of selecting it.
4 Double-click your selection, click OK, or press Enter.
The new node appears inside the project in the project pane.

Removing material from a project


You can remove folders, files, classes, and packages from your project
without deleting them from the drive.
Use the Remove From Project dialog box.
1 To access this dialog box, either:
• Right-click the node you want to remove and choose Remove From
Project from the context menu.
• Select it and click the Remove From Project button.
2 Click OK or press Enter in the Remove From Project dialog box.
Note If a folder contains files, they are also removed from the project.
You can also select multiple files and remove them from the project.

Creating and managing projects 6-15


Managing projects

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.

Opening a file outside of a project


Use the File|Open file command to open a file in the AppBrowser without
adding the file to the open project. A project must be open in order for this
option to be available.
To open a file without adding it to a project,
1 Choose File|Open File. The Open File dialog box appears.
2 Select the file you want to open.
3 Click OK. The file contents are displayed in the AppBrowser.
This is a feature of You can also open a file in the open project in another AppBrowser.
JBuilder SE and
Enterprise.
1 Right-click a file in the project pane.
2 Choose Open In New Browser.

Renaming projects and files


There are several ways to rename a project or one of its files.
1 Select the project or file in the project pane.
2 Select Project|Rename, File|Rename, or right-click in the project pane
and select Rename.
3 Enter the new name in the Rename dialog box.
4 Click Save.
There's also another way to rename an open file:
1 Right-click the file tab at the top of the content pane.
2 Select Rename.
3 Enter the new name in the Rename dialog box.
4 Click Save.
Note Renaming a file does not change the file type. To change the file extension,
use File|Save As.

6-16 Introducing JBuilder


Working with multiple projects

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

Working with multiple projects


You can work on multiple projects simultaneously in the JBuilder
development environment. You can open them in one AppBrowser or in
different AppBrowsers. All open projects are available from any open
AppBrowser from the Project drop-down list. Any changes made in one
AppBrowser are also made in any other open AppBrowsers displaying
the same project. Open a new JBuilder AppBrowser by selecting
Window|New Browser.

Switching between projects


If several projects are open in the AppBrowser, only one project is visible
in the project pane. Switch to another open project by selecting the project
from the Project drop-down list on the toolbar above the project pane.
Open AppBrowsers, projects, and files are all available from the Window
menu:

Creating and managing projects 6-17


Working with multiple projects

Select New Browser to open another AppBrowser. Control the browser


windows with the next four commands. Select either the open file or the
project file that belongs to an alternate AppBrowser to switch between
browser windows.
Open files in the current browser are also available from this menu. This
provides an alternate way to access open files—especially helpful for
those who prefer not to show file names on file tabs.

Saving multiple projects


To save changes to all open files and projects, choose File|Save All. All
files in all open AppBrowsers are saved.

6-18 Introducing JBuilder


Chapter

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.

Working with libraries


What is a library?
JBuilder uses libraries to find everything it needs to run a project as well
as for browsing through source, viewing Javadoc, using the visual
designer, applying CodeInsight, and compiling code. Libraries are
collections of paths that include classes, source files, and documentation
files. Libraries are static, not dynamic. Individual library paths are often
contained in JAR or ZIP files but can also be contained in directories.
When libraries are added to JBuilder, they are added to the class path so
JBuilder can find them. Libraries are searched in the order listed. The
order of libraries can be changed in the Configure Libraries dialog box
(Tools|Configure Libraries) and on the Paths page of the Project
Properties dialog box (Project|Project Properties).

Managing paths 7-1


Working with libraries

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.

Adding and configuring libraries


There are several ways to add new libraries to your project. First, you may
want to gather your files into JAR files, especially if you plan to deploy
your program.
Once you've created the library, add it to JBuilder as follows:
1 Select Tools|Configure Libraries. The Configure Libraries dialog box
appears.
The left-hand pane lets you browse the available libraries. The right-
hand pane shows the settings of the selected library.

7-2 Introducing JBuilder


Working with libraries

2 Click the New button under the left pane to open the New Library wizard.

3 Enter a name for the new library in the Name field.


4 Select a location from the drop-down list to save the library
configurations: Project, User Home, JBuilder, or user-defined folder.
User-defined folders are a feature of Enterprise.
5 Click the Add button and select one or more paths containing class,
source, and documentation files. JBuilder automatically determines the
correct path for the files. Click OK. Notice that the selection appears in
the Library Paths list.
6 Click OK to close the New Library wizard. Note that the library is
saved to the appropriate class, source, and documentation paths in the
Configure Libraries dialog box. You can also add, edit, remove, and
reorder the library lists in this dialog box. JBuilder Enterprise also
includes an Add Folder feature.

Managing paths 7-3


Working with libraries

7 Click OK or press Enter to close the Configure Libraries dialog box.


To add the library to a project, see “Setting paths for required libraries” on
page 7-10.
You can also add libraries in the Project Properties dialog box.
1 Select Project|Project Properties.
2 Select the Required Libraries tab on the Paths page and click the Add
button.
3 Click the New button 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.

7-4 Introducing JBuilder


Setting project properties

Display of library lists


There are three possible colors for libraries listed in JBuilder dialog boxes:

Table 7.1 Colors in library lists


Color Description Troubleshooting
Black The library is defined
correctly.
Red The library definition is This typically means the project refers to a
missing. library that is not yet defined. It can also mean
that the library definition is faulty: either the
library has been defined without any paths or
there is more than one library with that name.
Gray Use of this library You need to upgrade your edition of JBuilder
requires an upgrade. in order to use this library. For example, if
you have JBuilder Personal, use of the
dbSwing library requires that you upgrade to
either JBuilder Enterprise.

Setting project properties


Project properties control how the project is compiled. In the Project
Properties dialog box (Project|Project Properties), you can set such
options as:
• Paths page: set project path settings for the JDK version, output path,
backup path, working directory, source paths, test path, documentation
path, and required libraries paths.
• General page: set options for encoding, enabling automatic source
packages, modify class Javadoc fields that wizards can generate, and
set the option to include references from project libraries.
• Run page: select or create a configuration to use for running or
debugging.
• Build page: set compiler options for building a project, including debug
information and selective resource copying.
• Code Style page: set options for customizing your coding style on a
project-by-project basis.
This is a feature of • Import Style page: set options for configuring import statements.
JBuilder SE and
Enterprise
• Editor page: set end of line characters.

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.

Managing paths 7-5


Setting project properties

This is a feature of • Server page: select a server for the project.


JBuilder Enterprise
This is a feature of • Server page: set server options.
JBuilder Enterprise
Note You can also set these options for all future projects in the Default
Project Properties dialog box (Project|Default Project Properties) or
select the default project as your project template in the Project wizard.
To set project properties,
1 Right-click the .jpx file name in the project pane and choose Properties
to display the Project Properties dialog box. Or, select the project and
choose Project|Project Properties. The Project Properties dialog box
appears.
2 Select the appropriate tab for the options you want to set. In this image
the Paths page is selected.
On the Paths page, you can set the JDK version, various paths for the
project, and the Required Libraries Paths.

Setting the JDK


JBuilder SE and Enterprise fully support JDK switching, while JBuilder
Personal allows you to edit a single JDK. JBuilder compiles and runs
against all Sun JDKs and many others.
With JBuilder SE and Enterprise, you can set the JDK version for your
project on the Paths page of the Project Properties dialog box as well as

7-6 Introducing JBuilder


Setting project properties

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.

Editing the JDK


You can edit the current JDK version as follows:
1 Select Tools|Configure JDKs to open the Configure JDKs dialog box:

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.

Debugging with -classic


The Always Debug With -Classic option in the Configure JDKs dialog box
provides improved performance for users with JVM versions below 1.3.1.
JBuilder automatically checks to see if this option will improve your
performance, then checks or unchecks this box according to what will give
you the best results. This feature is available in all editions of JBuilder.

Managing paths 7-7


Setting project properties

In performing its evaluation, JBuilder performs two checks:


1 Do you have the Classic VM?
2 If present, is the JVM a version earlier than 1.3.1?
This selection is overridden when you define VM parameters such as
native, hotspot, green, or server.

Setting the JDK in SE and Enterprise


JBuilder SE and Enterprise support JDK switching. You can also add, edit,
and delete JDKs. To switch to another JDK, follow these steps:
1 Select Project|Project Properties and select the Paths tab.
2 Click the ellipsis button to the right of the JDK version. The Select A
JDK dialog box appears:

3 If the target JDK is listed, select it and press OK.

7-8 Introducing JBuilder


Setting project properties

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.

Managing paths 7-9


Setting project properties

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.

Setting paths for required libraries


On the Paths page of the Project Properties dialog box, you can set the
libraries to use when compiling. JBuilder places any selected libraries on
the classpath. To add, edit, remove, and reorder libraries, select the
Required Libraries tab.

7-10 Introducing JBuilder


Packages

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.

You can also configure libraries by selecting Tools|Configure Libraries.

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.

Managing paths 7-11


Packages

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.

If the individual classes contained in this project are Lion.class,


Cheetah.class, and Leopard.class, these would be found in classes/feline/
africa. The source files, Lion.java, Cheetah.java, and Leopard.java, would
be in found in src/feline/africa as shown here.

.java file location = source path + package path


It's important to understand what pieces of information JBuilder uses to
build the directory location for any given .java file. The first part of the
directory path is determined by the Source path. The source path is
defined at the project level and can be modified on the Paths page of the
Project Properties dialog box.

7-12 Introducing JBuilder


Packages

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

.class file location = output path + package path


The directory location for the .class file is determined by the Output path
and the package name. The output path is the “root” to which JBuilder
will add package paths to create the directory structure for the .class files
generated by the compiler. The output path is defined at the project level
and can be modified on the Paths page of the Project Properties dialog
box.
In the SampleProject example, the output path for Lion.class is:
/<home>/<username>/jbproject/SampleProject/classes
The second part of the directory path is determined by the package name,
which in this case is feline.africa.
As shown below, the .class location for Lion.class is:
/<home>/<username>/jbproject/SampleProject/classes/feline/africa/Lion.class

See also
• “How JBuilder constructs paths” on page 7-14

Using packages in JBuilder


When referencing classes from a package, you can use an import
statement for convenience. An import statement allows you to reference
any class in the imported package just by using the short name in the

Managing paths 7-13


How JBuilder constructs paths

code. (JBuilder's designers and wizards add import statements


automatically.) Here's an example of an import statement:
import feline.africa.*;
If this import statement is included in your source code, you could refer to
the Lion class as just Lion in the body of the code.
If you don't import the package, you must reference a particular class in
your code with its fully qualified class name. As shown in the following
diagram, the fully qualified class name for Lion.java is feline.africa.Lion
(package name + class name without the extension).

Packages can be selectively excluded from the build process.

See also
• Filtering packages in Building Applications with JBuilder.

Package naming guidelines


The following package naming guidelines are recommended for use in all
Java programs. To encourage consistency, readability, and
maintainability, package names should be
• One word
• Singular, rather than plural
• All lowercase, even if more than one word (for example,
fourwordpackagename not FourWordPackageName)
If your packages will be shared outside your group, package names
should start with an Internet domain name with the elements listed in
reverse order. For example, if you were using the domain name
foo.domain.com, your package names should be prefixed with
com.domain.foo.

How JBuilder constructs paths


The JBuilder IDE uses several paths during processing:
• Source path
• Output path
• Class path

7-14 Introducing JBuilder


How JBuilder constructs paths

• 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

Managing paths 7-15


How JBuilder constructs paths

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

7-16 Introducing JBuilder


Where are my files?

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.

Where are my files?


Each file in a project is stored with a relative path to the location of the
project file. JBuilder uses the Source path, test path, Class path, browse
path, and Output path to find and save files.
• The source path controls where the compiler looks for source files.
• The test path serves as the source path when you're using unit testing.

Managing paths 7-17


Where are my files?

• 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

How JBuilder finds files when you drill down


When you drill down to explore source code, JBuilder searches for the
.java files using the Browse path. For more information about drilling
down, see “Navigating in the source code” on page 4-9.

How JBuilder finds files when you compile


When you compile your project, JBuilder uses the following paths:
• class path
• source path
• output path
JBuilder looks in the class path to find the location of the .class files, the
libraries to use, and the target JDK version to compile against. The
compiler compares the .class files with their source files, located in the
source path, and determines if the .class files need to be recompiled to
bring them up to date. The resulting .class files are placed in the specified
output path.
For information about compiling files, see “Building and compiling Java
programs” in Building Applications with JBuilder.

How JBuilder finds class files when you run or debug


When you run and debug your program, JBuilder uses the class path to
locate all classes your program uses.
When you step through code with the debugger, JBuilder uses the browse
path to find source files.
For information about debugging files, see “Debugging Java programs” in
Building Applications with JBuilder.

7-18 Introducing JBuilder


Chapter

Comparing files and versions


Chapter8
8
This is a feature of JBuilder provides many ways to compare files, view differences between
JBuilder SE and different files and between different versions of the same file, and to
Enterprise. manage, merge, and revert file differences. The Compare Files dialog box
and the History pages provide access to these features.

Version handling glossary


Certain specialized terms are used in this section:

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.

Comparing files and versions 8-1


Comparing two files

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.

Comparing two files


JBuilder's Compare Files dialog box allows you to compare any two files.
To compare any two text-based files,
1 Choose File|Compare Files. The Select Old File navigation dialog box
appears:

2 Select the first file and click OK. The Select New File dialog box
appears.

8-2 Introducing JBuilder


Comparing two files

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.

Comparing files and versions 8-3


Using the history view

Using the history view


The history view lets you see prior versions of a file using any available
file version type, including multiple backup versions, saved local changes,
and the buffer of an active file. If the current file is under version control,
all types of revisions are available in the history view; if not, the history
view uses backups, saved changes, and the unsaved buffer to allow you to
manage revisions.
Since the history view is in the content pane, its pages reflect the currently
active file. Double-click a file in the project pane to make it active. Click an
open file's file tab in the content pane to make it active.
There are three pages in the history view. They provide the following
features:
• The Contents page, available in all editions of JBuilder, displays current
and previous versions of the file.
• The Diff page, available in JBuilder SE and Enterprise, displays
differences between selected versions of the file.
• The Info page, available in JBuilder Enterprise, displays all labels and
comments on the active file.
All three pages have revision tables that list all versions of the active file.
The revision lists show the version number of the file, the type and date of
revision, and other information. You can sort the revision lists by clicking
on the column head of the characteristic you want to sort by. JBuilder uses
the following icons in the revision tables to distinguish different version
control types:

Icon Description
A backup version of the file.

The latest saved 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.

A file version from a version control system.

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

8-4 Introducing JBuilder


Using the history view

cannot edit the source viewer directly. This simplifies retrieving old work
while it protects the integrity of the prior file versions.

Refresh Revision Info


The Refresh Revision Info button updates your view of the revision list to
include any changes made by other users to the file in the repository. It is
useful under version control only. This button is available from all three
History pages.

Revert To Previous Revision


The Info page is a feature The Revert To Previous Revision button makes the version you have
of JBuilder Enterprise. selected the most current version again. The old version becomes the most
recent. This button is available from the Contents and Info pages.
Note Reverting to a prior version loses all unsaved changes in the editor buffer.
Under version control, all of the intermediate versions are retained in the
repository.

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

Comparing files and versions 8-5


Using the history view

the sort order. Select a version in the revision list to view its source in the
source viewer:

The Refresh Revision Info, Revert To Previous Revision, and Synchronize


Scrolling buttons are enabled on this page.

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

8-6 Introducing JBuilder


Using the history view

version in the To list. The differences will be displayed in the source


viewer below the lists:

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.

Comparing files and versions 8-7


Using the history view

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.

8-8 Introducing JBuilder


Chapter

Tutorial: Building an application


Chapter9
9
This tutorial gets you up and running using the JBuilder integrated
development environment (IDE). The tutorial shows how to:
• Create a project for the application.
• Create a simple “Hello World” application.
• Compile and run the application.
• Modify the user interface of an application.
• Add Swing components, such as JPanel, JLabel, and JButton.
• Edit the source code.
• Run the application from the command line.
• Add an event method to a button.
• Complete the UI.
These are features of • Bundle the files for deployment.
JBuilder SE and
• Run the deployed application from the command line.
Enterprise.

Tutorial: Building an application 9-1


Step 1: Creating the project

When you have completed the tutorial, you will have a Java application
that looks like this:

For information on documentation conventions used in this tutorial, see


“Documentation conventions” on page 1-2.
For the complete source code, see the “HelloWorld source code” on
page 9-23.

Step 1: Creating the project


Before creating an application in JBuilder, you must first create a project to
work in. JBuilder uses a project file with a .jpx extension to organize the
application files and maintain the settings and project properties. The
Project wizard can create a project for you.
1 Choose File|New Project to open the Project wizard.
2 Make the following changes to the appropriate fields in Step 1 of the
Project wizard:
a Type HelloWorld in the Name field.
Note As you type the project name in the Name field, the same name is
entered in the Directory field. By default, JBuilder uses this project
name to create the project's directory name and the package name
for the classes. The package name is forced to lowercase according to
the Java convention for naming packages. Projects in JBuilder are
saved by default in the /<home>/jbproject/ directory. The home
directory varies by platform. See “Documentation conventions” on
page 1-2. For more information on projects, see Chapter 6, “Creating
and managing projects.”
b Accept jpx as the project file type.
c Check the Generate Project Notes File option.
When you check this option, the Project wizard creates an HTML file
for project notes and adds it to the project.

9-2 Introducing JBuilder


Step 1: Creating the project

Step 1 of the Project wizard should look similar to this:

3 Accept all other defaults in Step 1.


4 Click Next to go to Step 2 of the Project wizard.
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
Chapter 7, “Managing paths.”
Step 2 of the Project wizard should look similar to this:

Tutorial: Building an application 9-3


Step 1: Creating the project

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 Hello World in the Title field of the class Javadoc fields.
and Enterprise. c Enter your name, company name, and a description of your
application 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.
Step 3 of the Project wizard looks similar to this:

8 Click the Finish button.


Two files, HelloWorld.jpx and HelloWorld.html, are generated by the
wizard and appear in the project pane located in the upper left of
JBuilder's AppBrowser.

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.

9-4 Introducing JBuilder


Step 2: Generating your source files

Step 2: Generating your source files


The Application wizard creates .java source files that are added to the
project you just created.
To generate source files for your application using the Application
wizard, follow these steps:
1 Choose File|New or click the New button on the main toolbar to open
the object gallery.

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.

Tutorial: Building an application 9-5


Step 2: Generating your source files

Step 1 of the Application wizard should look like this:

6 Click the Next button to go to Step 2 of the Application wizard.


7 Type HelloWorldFrame in the Class field to name the Frame class.
8 Type Hello World in the Title field.
This text appears in the title bar of the frame in your application.
9 Check all of the options for additional application features: Generate
Menu Bar, Generate Toolbar, Generate Status Bar, Generate About
Dialog, and Center Frame On Screen. The wizard generates the basic
code to support these features.
Step 2 of the Application wizard should look like this:

9-6 Introducing JBuilder


Step 2: Generating your source files

10 Click the Finish button.


The new .java source files and toolbar images are added to your project
and displayed as nodes in the project pane. The source code for
HelloWorldFrame.java is open in the content pane as shown in the
following image.
Note In JBuilder SE and Enterprise editions, an automatic source package
node named helloworld also appears in the project pane if the Enable
Source Package Discovery And Compilation option is enabled on the
General page of the Project Properties dialog box (Project|Project
Properties).
Figure 9.1 AppBrowser elements

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.

Tutorial: Building an application 9-7


Step 3: Compiling and running your application

Step 3: Compiling and running your application


Now, compile and run the application. Compiling is the process of
running the Java compiler. The compiler, which translates source code
into Java bytecode, generates .class files.
1 Choose Run|Run Project or click the Run Project button to compile and
run your application.
Tip You can also select HelloWorldClass.java in the project pane, right-click,
and choose Run using “HelloWorldClass”.
First, the message pane opens displaying the run process. Then, your
application is displayed and should look like this:

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.

Step 4: Customizing your application's user interface


Follow these steps to customize your application's user interface:
1 Double-click HelloWorldFrame.java in the project pane if it's not already
open.
2 Click the Design tab at the bottom of the content pane to change to
design view.
The UI designer appears in the content pane with the component
palette above it and the Inspector on the right. You use the component
palette to add components to your UI and the Inspector to modify
properties and add events to your code. The structure pane, located to
the left of the content pane, now contains a component tree containing
components and such folders as UI, Menu, and Other.

9-8 Introducing JBuilder


Step 4: Customizing your application's user interface

Figure 9.2 UI designer elements

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.

Tutorial: Building an application 9-9


Step 4: Customizing your application's user interface

jPanel1 is now selected in your application design and in the


component tree.

Note: The component selected in the component tree or the UI designer


displays in the status bar below the structure pane.
5 Set the background color of jPanel1 to White.
a Click the column to the right of the background property in the
Inspector.
b Click the Down arrow to open the color drop-down list and select
White at the top of the list.
Note: If you click too far right in the column, the Background dialog box
opens. You can also choose white by entering 255 for each red, green,
and blue value.
6 Add a line border to jPanel1 and change the border color to Gray.
a Click the column to the right of the border property in the Inspector.
b Click the Down arrow to open the border drop-down list and select
Line.
c Select the ellipsis button to access the Border dialog box.
d Click Black under Options|Color to access the color drop-down list
and select Gray.
e Click OK to close the Border dialog box.
7 Change the layout manager for jPanel1 to null.
a Click the column to the right of the layout property in the Inspector.
b Choose null from the drop-down list.
null, or no layout, is a good choice when prototyping your design.
Because null does not use a layout manager, you can place components
exactly where you want them. However, because null uses absolute
positioning of components instead of relative positioning, the UI will
not resize properly when the user resizes the application window.
Therefore, it's recommended that you never leave a container in null for

9-10 Introducing JBuilder


Step 5: Adding a component to your application

deployment. Later in the tutorial, you'll switch to an appropriate


portable layout for your design before deploying it.
8 Choose File|Save all to save the project.

Step 5: Adding a component to your application


Now, you'll use the component palette to add a JLabel component to the
JPanel component.
1 Select the Swing tab on the component palette and click the JLabel
component.

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.

Tutorial: Building an application 9-11


Step 6: Editing your source code

e Click the column to the right of the foreground property in the


Inspector to set the color of the “Hello World!” text. Click the Down
arrow and select Blue from the drop-down list of colors.
Your design now looks similar to this:

5 Choose File|Save All.

Step 6: Editing your source code


You can change information in the About box by directly editing the code.
The default application version created by the Application wizard is
version 1.0.
1 Double-click HelloWorldFrame_AboutBox.java in the project pane to open
the file.
The content pane changes to the source view where you can edit the
code in the editor.
2 Choose Search|Find to open the Find/Replace Text dialog box.
3 Type the following line of code in the Text to Find list box:
String version = "1.0";

9-12 Introducing JBuilder


Step 7: Compiling and running your application

4 Click Find.
The editor finds the selected text.

5 Select 1.0 and enter 2.0 inside the quotes.


6 Choose File|Save All.

Step 7: Compiling and running your application


Now you can compile and run the application.
1 Choose Project|Make Project “HelloWorld.jpx” to compile the project.
2 Choose Run|Run Project.

Tutorial: Building an application 9-13


Step 8: Running your application from the command line

The “Hello World” application is displayed:

3 Choose Help|About. The version data you changed is now displayed


in the About dialog box.

4 Click OK to close the dialog box.


5 Choose File|Exit in your “Hello World” application to close it.

Step 8: Running your application from the command line


You can also run the application outside the JBuilder environment from
the command line.
Note The <jdk>/bin/ directory which contains the java command must be on
your path. If java is on your path, when you type java at the command
line, information explaining the command should display. If it's not on
your path, you need to run the application from within the <jdk>/bin/
directory.

9-14 Introducing JBuilder


Step 9: Adding an event to a button

To run the application, assuming java is on your path,


1 Open the command-line window.
2 Run the application with the following command on one line at the
command prompt:
java -classpath
/<home>/jbproject/HelloWorld/classes helloworld.HelloWorldClass
Note For Windows, use a backslash (\).
This command should be in the following form:
java -classpath classpath package-name.main-class-name
In this example,
• java = the launcher for the Java application.
• -classpath = an option that sets the search path for application classes
and resources.
• classpath = /<home>/jbproject/HelloWorld/classes
The classpath should point to the directory containing the compiled
classes. In this example, the classes directory was set as the output
path for compiled classes on Step 1 of the Project wizard.
• <home> = your home directory, for example, c:\winnt\profiles\
<username>
• package-name = helloworld
• main-class-name = HelloWorldClass
3 Close the “Hello World” application.

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

Step 9: Adding an event to a button


Next, you'll add another Swing component to your application.
1 Open HelloWorldFrame.java and click the Design tab to switch to the UI
designer.

Tutorial: Building an application 9-15


Step 9: Adding an event to a button

2 Click the JButton component on the Swing tab of the component


palette and drop it on either jPanel1 in the component tree or in the
panel in your design. jButton4 is added below jPanel1 in the component
tree.
3 Click jButton4 in the design and drag it to the top center of the design as
shown in the image below.

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.

9-16 Introducing JBuilder


Step 9: Adding an event to a button

6 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.
void jButton4_actionPerformed(ActionEvent e) {

}
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.

12 Choose File|Exit to close the “Hello World”application.

Tutorial: Building an application 9-17


Step 10: Completing your UI

Step 10: Completing your UI


As the final step in completing your application, you need to change your
layout to a portable layout. Remember, if you leave jPanel1 as null or no
layout, the components in your UI will not reposition when the user
resizes the application window at runtime. Because null uses absolute
positioning, the components remain in the same location, no matter what
size the window. Therefore, null is not a good layout manager for final
deployment of your application.
To demonstrate this window resizing problem with null, run the
application as follows:
1 Right-click HelloWorldClass.java, which contains the main() method, and
choose Run.
2 Resize the “Hello World” application window, making it larger and
smaller, and observe the behavior of the components.
Notice that the label and button components do not move as you resize
the window, because their position is absolute rather than relative to
the window size.

3 Close the “Hello World” application.


Portable layouts, unlike null, use relative positioning which is dynamic.
Components in portable layouts reposition correctly when the user resizes
the application window. In this example, you'll change the layout to
GridBagLayout. For more information on layouts, see “Using layout
managers” in Designing User Interfaces.
To modify the layout behavior,
1 Return to the HelloWorldFrame.java file in the content pane and click the
Design tab to switch to the designer.
2 Choose jPanel1 in the component tree.
3 Choose the Inspector's Properties tab.

9-18 Introducing JBuilder


Step 11: Preparing your application for deployment

4 Change jPanel1's layout property to GridBagLayout in the Inspector. Select


each component in the designer and notice the grid area each
component fills.
GridBagLayout is a good choice for laying out components of varying
sizes in a grid. See “GridBagLayout” in Designing User Interfaces.
5 Save and run the application.
6 Resize the application window and notice how the components
reposition as the window changes in size.

7 Close the “Hello World” application.


If you are using JBuilder Personal, you have completed the tutorial.
Congratulations!

Step 11: Preparing your application for deployment


Steps 11 and 12 use The Archive Builder collects all the files needed to distribute your
features found in JBuilder program and can archive them into a Java archive file (JAR file).
SE and Enterprise.
To deploy your application:
1 Choose Wizards|Archive Builder to open the Archive Builder.

Tutorial: Building an application 9-19


Step 11: Preparing your application for deployment

2 Select Application from the Archive Type drop-down list.

3 Click Next to go to Step 2.


4 Accept the defaults in Step 2.
Note that HelloWorld.jar will be saved to the HelloWorld directory.

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.

9-20 Introducing JBuilder


Step 11: Preparing your application for deployment

7 Right-click the Application node and choose Make or choose Project|


Make Project “HelloWorld.jpx” to compile your application and create
the JAR file.
The Archive Builder gathers all the files in the project's output path
(Project|Project Properties|Paths) into the JAR file.
8 Click the expand icon next to the Application archive node to expand
the node and see the HelloWorld.jar archive file.
9 Double-click the JAR file in the project pane.
The manifest file appears in the content pane and the contents of the
JAR file appear in the structure pane.

10 Save your project.


For more information on deployment, see “Deploying Java programs” in
Building Applications with JBuilder.

Tutorial: Building an application 9-21


Step 12: Running your deployed application from the command line

Step 12: Running your deployed application from the


command line
Continue with the tutorial To test the deployed application, you can run the JAR file from the
if you have JBuilder SE or command line.
Enterprise.
Note The <jdk>/bin/ directory which contains the java command must be on
your path. If java is on your path, when you type java at the command
line, information explaining the command should display. If it's not on
your path, you need to run the application from within the <jdk>/bin/
directory.
1 Open the command-line window.
2 Enter the following command on one line at the prompt:
java -classpath /<home>/jbproject/HelloWorld/HelloWorld.jar
helloworld.HelloWorldClass
Note For Windows, use a backslash (\).
The command must have the following form:
java -classpath classpath package-name.main-class-name
In this example,
• java = the launcher for the Java application
• -classpath = an option that sets the search path for application classes
and resources.
• classpath = /<home>/jbproject/HelloWorld/HelloWorld.jar
The classpath should include the JAR file and its correct location. In
this example, the JAR file is located in the project directory,
HelloWorld. The Archive Builder saves it there by default.
• <home> = your home directory, for example, c:\winnt\profiles\
<username>
• package-name = helloworld
• main-class-name = HelloWorldClass
For information on JAR files, see the JAR tutorial at http://
java.sun.com/docs/books/tutorial/jar/index.html.
3 The “Hello World” application loads and runs.
Congratulations, you've created your first application with JBuilder. Now
that you're familiar with JBuilder's development environment, you'll find
its many time-saving features make your programming easier.
For other tutorials involving UI design in JBuilder, see “Text editor,”
”GridBagLayout,” and “Nested layouts” in Designing User Interfaces.

9-22 Introducing JBuilder


HelloWorld source code

HelloWorld source code


Source code for HelloWorldFrame.java
package helloworld;

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
*/

public class HelloWorldFrame extends JFrame {


JPanel contentPane;
JMenuBar jMenuBar1 = new JMenuBar();
JMenu jMenuFile = new JMenu();
JMenuItem jMenuFileExit = new JMenuItem();
JMenu jMenuHelp = new JMenu();
JMenuItem jMenuHelpAbout = new JMenuItem();
JToolBar jToolBar = new JToolBar();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
ImageIcon image1;
ImageIcon image2;
ImageIcon image3;
JLabel statusBar = new JLabel();
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
Border border1;
JLabel jLabel1 = new JLabel();
JButton jButton4 = new JButton();
GridBagLayout gridBagLayout1 = new GridBagLayout();
/**Construct the frame*/
public HelloWorldFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}

Tutorial: Building an application 9-23


HelloWorld source code

/**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);

9-24 Introducing JBuilder


HelloWorld source code

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));
}
}

Tutorial: Building an application 9-25


HelloWorld source code

Source code for HelloWorldClass.java


package helloworld;

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
*/

public class HelloWorldClass {


boolean packFrame = false;

/**Construct the application*/


public HelloWorldClass() {
HelloWorldFrame frame = new HelloWorldFrame();
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
frame.pack();
}
else {
frame.validate();
}
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}
/**Main method*/
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
e.printStackTrace();
}
new HelloWorldClass();
}
}

9-26 Introducing JBuilder


HelloWorld source code

Source code for HelloWorldFrame_AboutBox.java


package helloworld;

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
*/

public class HelloWorldFrame_AboutBox extends JDialog implements ActionListener


{

JPanel panel1 = new JPanel();


JPanel panel2 = new JPanel();
JPanel insetsPanel1 = new JPanel();
JPanel insetsPanel2 = new JPanel();
JPanel insetsPanel3 = new JPanel();
JButton button1 = new JButton();
JLabel imageLabel = new JLabel();
JLabel label1 = new JLabel();
JLabel label2 = new JLabel();
JLabel label3 = new JLabel();
JLabel label4 = new JLabel();
BorderLayout borderLayout1 = new BorderLayout();
BorderLayout borderLayout2 = new BorderLayout();
FlowLayout flowLayout1 = new FlowLayout();
GridLayout gridLayout1 = new GridLayout();
String product = "";
String version = "2.0";
String copyright = "Copyright (c) 2001";
String comments = "";
public HelloWorldFrame_AboutBox(Frame parent) {
super(parent);
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
pack();
}

Tutorial: Building an application 9-27


HelloWorld source code

/**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();
}
}
}

9-28 Introducing JBuilder


Chapter

Tutorial: Building an applet


Chapter10
10
This tutorial steps you through creating an AWT applet using the JBuilder
integrated development environment (IDE). For more information on the
IDE and its components, see “JBuilder environment” available from the
Help menu.
The tutorial shows how to:
• Create a project for the applet.
• Use the Applet wizard to create an AWT applet.
• Compile and run the applet.
• Customize the applet's UI.
• Add AWT components, such as Choice, Label, and Button.
• Edit the source code.
• Deploy the applet.
• Modify the HTML file.
• Run the deployed applet from the command line.
• Test the applet.
Tip The applet source code is provided at the end of the tutorial. The
FirstApplet sample is available in samples/Tutorials/FirstApplet in your
JBuilder directory.
Important If you have installed JBuilder as root but are running as a regular user,
you need to copy the entire samples tree to a directory in which you have
full read/write permissions in order to run them.
Important Before beginning this tutorial, read the overview which discusses
important applet issues.

Tutorial: Building an applet 10-1


Overview

For information on documentation conventions used in this tutorial, see


“Documentation conventions” on page 1-2.

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.

10-2 Introducing JBuilder


Step 1: Creating the project

Good Evening applet


The “Good Evening” applet you create in this tutorial contains a drop-
down list of language choices. When you select a language, such as
German, the panel below the selection changes to the German translation
of “Good Evening”: “Guten Abend.”
When you finish the tutorial, your applet will look similar to this when
running in JBuilder's applet viewer:

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.

Step 1: Creating the project


Before beginning this tutorial, read the “Overview” on page 10-2 which
discusses such important applet issues as browser support, JDK versions,
and applet components.
Before creating your applet, you need a project in which to store it. The
Project wizard creates one for you:
1 Choose File|New Project to open the Project wizard.
2 Make the following changes to the appropriate fields in Step 1 of the
Project wizard:
a Type FirstApplet in the Name field.
Note As you type the project name in the Name field, the same name is
entered in the Directory field. By default, JBuilder uses this project
name to create the project's directory name and the package name
for the classes. Projects in JBuilder are saved by default in the /
<home>/jbproject/ directory. See “Documentation conventions” on

Tutorial: Building an applet 10-3


Step 1: Creating the project

page 1-2. For more information on projects, see “Creating and


managing projects” on page 6-1.
b Choose jpx from the Type drop-down menu.
c Check the Generate Project Notes File option.
When you check this option, the Project wizard creates an HTML file
for project notes and adds it to the project.
3 Accept all other defaults in Step 1.

4 Click Next to go to Step 2 of the Project wizard.

10-4 Introducing JBuilder


Step 1: Creating the project

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.

Tutorial: Building an applet 10-5


Step 1: Creating the project

Note The information in the class Javadoc fields appears in the project
HTML file and as optional header comments in the source code.

8 Click the Finish button.


The wizard creates a project file and a project notes file, FirstApplet.jpx
and FirstApplet.html, that appear in the project pane of the
AppBrowser.
9 Double-click the HTML file to see the project notes in the content pane.

10-6 Introducing JBuilder


Step 2: Generating your source files

Step 2: Generating your source files


The Applet wizard creates a .java file and an applet HTML file and places
them in the project you just created with the Project wizard.
To generate these source files for your applet, follow these steps:
1 Choose File|New and choose the Web tab of the object gallery.
2 Double-click the Applet icon to open the Applet wizard.
3 Accept the default package name, firstapplet, in Step 1. By default, the
wizard takes the package name from the project file name,
FirstApplet.jpx.
4 Type GoodEveningApplet in the Class Name field.
This is a case-sensitive Java class name.
Note The fully qualified class name (package name + class name) is
firstapplet.GoodEveningApplet.class.
5 Accept the default Base Class, java.applet.Applet.
Caution If you create your applet using javax.swing.JApplet, your applet won't
run in most web browsers. At the time of this writing, Swing is not yet
supported by the web browsers. See “Overview” on page 10-2 for more
information.
6 Check Generate Standard Methods.
Step 1 of the Applet wizard should look like this:

7 Click Next to go to Step 2.


In this step, you can add parameters to your applet. The wizard adds
the <param> tags inside the <applet> tags in the applet's HTML file and
also inserts code for handling parameters in the source code. Applet

Tutorial: Building an applet 10-7


Step 2: Generating your source files

parameters, the equivalent of command-line arguments for


applications, allow you to customize your applet. Do not add any
parameters in this tutorial.

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.

10-8 Introducing JBuilder


Step 2: Generating your source files

• 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

Tutorial: Building an applet 10-9


Step 2: Generating your source files

General page of the Project Properties dialog box (Project|Project


Properties).

Now, look at the source code for the two files.


1 Look at GoodEveningApplet.java and note the following:
• It contains the init() method. The applet HTML file must call the
class that contains the init() method for the applet to run.
• The package name firstapplet is the first line of code. The class file is
saved in a firstapplet directory according to Java conventions.
• The import statements import AWT packages, not Swing:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
2 Double-click GoodEveningApplet.html in the project pane and choose the
Source tab at the bottom of the content pane to see the source code.
Notice that the wizard inserted the code value,
firstapplet.GoodEveningApplet.class.

10-10 Introducing JBuilder


Step 3: Compiling and running your applet

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.

Step 3: Compiling and running your applet


Now, compile and run the applet. Compiling is the process of running the
Java compiler. The compiler, which translates source code into Java
bytecode, generates .class files.
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.
1 Choose Run|Run Project, or click the Run button to compile and run
your applet. The Run menu and the Run button run the applet in
JBuilder's applet viewer, AppletTestbed.
Tip You can also right-click GoodEveningApplet.html in the project pane and
select Run. This runs your applet in Sun's appletviewer.
Currently, the applet window is empty because the applet doesn't have
a user interface yet.
When you run your applet, the message pane appears at the bottom of
the AppBrowser where any compile-time errors are displayed. Correct
any errors and run the applet again.

Tutorial: Building an applet 10-11


Step 3: Compiling and running your applet

Your applet is displayed and should look like this in JBuilder's


AppletTestbed:

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.

10-12 Introducing JBuilder


Step 4: Customizing your applet's user interface

Step 4: Customizing your applet's user interface


Now that the Applet wizard has generated the applet shell, you'll
customize it with various components in the following steps.
1 Choose the GoodEveningApplet.java file tab at the top of the content pane.
2 Click the Design tab at the bottom of the content pane to change to
design view.
The UI designer appears in the content pane with the component
palette above it and the Inspector on its right. You'll use the component
palette to add components to your UI and the Inspector to modify
properties and add events to your code. The structure pane now
contains a component tree with such folders as UI, Menu, and Other.

3 Change the layout of the this element to BorderLayout in the Inspector:


a Select the this node in the component tree in the structure pane.
b Click to the right of the layout property on the Properties page of the
Inspector.

Tutorial: Building an applet 10-13


Step 4: Customizing your applet's user interface

c Select BorderLayout from the drop-down list of layouts.


BorderLayout arranges a container's components in areas named North,
South, East, West, and Center. Use BorderLayout when you want to force
components to one or more edges of a container or fill the center of the
container with a component. It is also the layout you want to use to
cause a single component to completely fill its container.
Caution If at any time you choose XYLayout (a custom Borland layout) from the
Inspector's drop-down list, JBuilder adds this import statement to the
source code: com.borland.jbcl.layout.*. This import statement is not
removed when you change to a more portable layout before
deployment. Your deployed applet won't run unless you remove this
import statement, because it will be looking for the jbcl layout classes to
import. You need to remove the import statement manually before
deploying.
JBuilder's UI designer uses a default layout manager for each container,
usually the layout of the AWT parent container. In the Java AWT, all
panels use FlowLayout by default. To see the panel's layout manager,
click the expand icon in the component tree to expand the selection.
The layout manager displays as an item in the tree just below the parent
container.

See also
• “Using layout managers” in Designing User Interfaces
• “Creating a UI with nested layouts” inDesigning User Interfaces

10-14 Introducing JBuilder


Step 4: Customizing your applet's user interface

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.

Tutorial: Building an applet 10-15


Step 4: Customizing your applet's user interface

2 Type upper and press Enter.


Tip You can also rename a component by right-clicking a component in
the component tree and selecting Rename from the menu.
f Rename the bottom panel to lower.

6 Change the background color of the upper panel to Orange in the


Inspector:
a Select the upper panel in the component tree or the designer.
b Click the column to the right of the background property in the
Inspector.
c Click the Down arrow to open the color drop-down list and select
Orange from the list.
7 Change the background color of lower to Magenta.

10-16 Introducing JBuilder


Step 4: Customizing your applet's user interface

8 Change lower's layout to CardLayout.


The CardLayout panel will contain 5 panels, each with “Good Evening”
in a different language. CardLayout places components (usually panels)
on top of each other in a stack like a deck of cards. You see only one at a
time, and you can flip through the panels by using another control to
select which panel comes to the top. CardLayout is usually associated
with a controlling component, such as a check box or a list. The state of
the controlling component determines which component the CardLayout
displays. The user makes the choice by selecting something on the UI.
9 Add 5 panels (panels 1 through 5) to the lower panel using Shift+Click
when selecting the Panel component. Each of these panels will have
“Good Evening” in a different language. Choose the Selection Tool to
deactivate Panel's multiple selection.
Note If you drop the component in the wrong location, select it in the
component tree and press Delete. Then add it again.
10 Change the layout for panels 1 through 5 to BorderLayout.
a Use Shift+Click or Ctrl+Click to select panels 1 through 5 in the
component tree.
b Change the layout property to BorderLayout in the Inspector. All 5
panels now have BorderLayout.
c Select another component in the component tree or the UI designer
to deselect all the panels.
11 Change the background color of each of these 5 panels to a different
color in the Inspector.
Tip Click the column to the right of the background property in the Inspector,
and click the ellipsis button to the right of the drop-down list to open
the Background dialog box. Use the color sliders in the Background
dialog box to create a color.
12 Save the file and the project.
13 Right-click GoodEveningApplet.html and select Run.
When the applet runs in Sun's appletviewer, you'll only see upper and
the top panel of the CardLayout. The other language panels display later
after you add the drop-down list and add the events to the list
selections.
14 Exit the applet.
15 Close the message pane by right-clicking the GoodEveningApplet tab
and selecting Remove “GoodEveningApplet” Tab.

Tutorial: Building an applet 10-17


Step 5: Adding AWT components to your applet

Step 5: Adding AWT components to your applet


Now you'll use the component palette to add a Label and a Choice
component to the top panel in your design, upper.
1 Select the AWT tab on the component palette and click the Choice
component.
2 Drop the component into your design's top orange panel, upper. Use
one of the following two methods:
• Click the upper panel in the component tree.
• Click the upper panel in the UI designer.
Note that choice1 is added to upper in the component tree.
3 Select the Label component on the AWT page of the component palette
and place it on the upper panel to the left of the Choice component.
Note that label1 is added to upper in the component tree.
4 Select label1 in the component tree and complete the following steps:
a Double-click the column to the right of the text property in the
Inspector to highlight the existing text.
b Enter Select a language and press Enter. “Select a language” now
appears in the label next to the Choice component.
c Click the column to the right of the font property to set the font.
Click the ellipsis button to open the Font dialog box.
d Choose Serif from the list of fonts and check Bold. Enter 20 in the Size
box, then click OK.
e Click the column to the right of the foreground property in the
Inspector to set the text color. Click the Down arrow and select Blue
from the drop-down list of colors.

10-18 Introducing JBuilder


Step 5: Adding AWT components to your applet

Your design should look similar to this:

5 Use Shift+Click to select the AWT label component on the component


palette, and add one label to each panel (1 through 5) on the lower
CardLayout panel.
Each of these labels will have “Good Evening” in a different language.
Remember to choose the Selection Tool on the left side of the
component palette to cancel the multiple selection feature.
6 Change each label to “Good Evening” in a different language. First,
select the label under each panel in the component tree and enter
“Good Evening” in the appropriate language in the text property of the
Inspector. Use these languages for the labels or choose your own:
• label2: Good Evening (English)
• label3: Guten Abend (German)
• label4: Oodgay vening eay (Pig Latin)
• label5: God Kväll (Swedish)
• label6: Gudday, Mate (Australian)
7 Select label2 through label6 using Ctrl+Click and change the font
properties for all the labels to Bold and the font size to 24. Change the
foreground property of the labels to Black. Click a component in the
component tree or in the UI designer to deselect the labels.

Tutorial: Building an applet 10-19


Step 5: Adding AWT components to your applet

8 Change the position of each label by changing the constraints property


in the Inspector to North, South, East, West, or Center as follows:
• label2: North
• label3: South
• label4: East
• label5: West
• label6: Center
Note Notice the position of each label (as indicated by the selection nibs) in
its BorderLayout panel. Center fills the entire panel, while North, South,
East, and West fill only a portion of the panel.
9 Change panel5's layout manager to FlowLayout, the same layout used for
the upper panel.
Notice that the “Gudday, Mate” label moves to the center top of the
panel. FlowLayout is a good layout choice when you want your
components in rows.
Next, you'll add a button, which FlowLayout will place in the same row
as the label. FlowLayout arranges components from left to right in a row.
When the row is full, the remaining components move to a new row.
10 Click the AWT Button component and drop it to the left of the “Gudday,
Mate” label.
Try moving the button to another position in the designer. FlowLayout
always forces it back into the row with the label. Your applet design for
panel5 should look similar to this:

11 Choose File|Save All to save the project.


For more information on layouts and their behaviors, see “Using layout
managers” and “Tutorial: Nested layouts” in Designing User Interfaces.

10-20 Introducing JBuilder


Step 6: Editing your source code

Step 6: Editing your source code


In this step, you'll add the languages to the drop-down list, then add
events to hook up each language panel to the Choice component.
1 Add the languages for the drop-down list to the init() method as
follows:
a Click the Source tab in the content pane to change to the source code
in the editor.
b Select the init() method in the structure pane. The init() method
code is highlighted in the editor.
Tip Search for a method in the structure pane by clicking in the structure
pane and typing the method name.
c Position the cursor after the opening curly brace and before the try/
catch statement and press Enter to create an extra blank line.
Tip To expand the editor and hide the project and structure pane, select
View|Toggle Curtain.
d Add the following code block indicated in bold to the init() method:
//initialize the applet
public void init() {
choice1.addItem("English");
choice1.addItem("German");
choice1.addItem("Pig Latin");
choice1.addItem("Swedish");
choice1.addItem("Australian");

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

Tutorial: Building an applet 10-21


Step 6: Editing your source code

configure CodeInsight in the Editor Options dialog box (Tools|


Editor Options|CodeInsight).

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");

10-22 Introducing JBuilder


Step 6: Editing your source code

}
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.

Tutorial: Building an applet 10-23


Step 6: Editing your source code

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:

4 Exit the applet.

10-24 Introducing JBuilder


Step 7: Deploying your applet

Step 7: Deploying your applet


Deploying a Java applet consists of bundling together the various Java
class files, image files, and other files needed by your applet and copying
them and the applet HTML file to a location on a server or client computer
where they can be executed. You can deliver the files separately, or you
can deliver them in compressed or uncompressed archive files. JAR files,
Java archive files, are the most commonly used. JAR files provide the
advantages of smaller file sizes and faster download times.
When deploying your applet, it's important to remember the following:
• Save and compile your project before deploying.
• Open GoodEveningApplet.html and click the Source tab to review the
following:
• Check that the code attribute has the fully qualified class name,
including the package name. In this example, the code value is
firstappplet.GoodEveningApplet.class.
• Check that the codebase attribute specifies the correct location of the
class file relative to the HTML file. In this example, the codebase value
is “.”, because the JAR file containing the class file will be in the
same directory as the HTML file.
• Maintain the existing directory structure. In this example,
GoodEveningApplet.class must be in a firstapplet directory to reflect the
package structure: firstapplet/GoodEveningApplet.class. If you're
deploying to a JAR file, check the directory structure in the file and
make sure it matches.
• Deliver all the necessary classes to the appropriate Internet server. The
class files must be in the correct location relative to the HTML file and
matching the codebase attribute.
• Deliver the applet HTML file to the appropriate Internet server.
Caution If you are creating your applets for older JDK 1.02-compliant browsers,
keep in mind that JAR files are not supported by these older browsers.
Create a ZIP archive file instead.

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

Tutorial: Building an applet 10-25


Step 7: Deploying your applet

Deploying your applet with the jar tool


JBuilder Personal The JDK includes a jar tool in the bin directory for creating JAR files for
deployment. The jar tool, an archiving and compression tool, combines
multiple files into a single JAR archive.
The basic jar command is in the following form:
jar {ctxu}[vfm0M] [jar-file] [manifest-file] [-C dir] files ...
Note For help on additional JAR options, enter jar -help at the command line or
see the jar documentation at http://java.sun.com/j2se/1.3/docs/
tooldocs/tools.html#basic.
Create the JAR file in the following steps:
1 Save your project.
2 Choose Project|Make Project “FirstApplet.jpx” to compile your project.
3 Create an applets directory for your applet in your /<home>/jbproject/
directory.
This will be the testing directory where you'll put your applet HTML
file and your JAR file.
4 Open the command-line shell or DOS window.
5 Change to the project directory: /<home>/jbproject/FirstApplet/
6 Enter the following JAR command:
jar cvf GoodEvening.jar -C classes firstapplet
Where:

jar is the command that generates the JAR file


c creates a new archive
v generates output specifying what has been added to the
JAR file
f specifies the name of the JAR file to create
-C changes temporarily to the specified directory during the
execution of the jar command (in this case the classes
directory)
classes the directory where the jar command is executed
firstapplet the package of classes to be added to the JAR file

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,

10-26 Introducing JBuilder


Step 7: Deploying your applet

jbuilder6/jdk1.3.1/.... If JBuilder is on another drive, include the drive


name before the JBuilder directory.
Note For Windows, use backslashes (\).
The jar tool outputs the results to the screen, which should look similar
to this:
added manifest
adding: firstappplet/(in = 0) (out= 0)(stored 0%)
adding: firstappplet/GoodEveningApplet.class(in = 5501) (out= 2683)(deflated 51%)
adding: firstappplet/GoodEveningApplet$1.class(in = 745) (out= 411)(deflated 44%)
adding: firstappplet/GoodEveningApplet$2.class(in = 741) (out= 409)(deflated 44%)
Notice the directory structure for the classes: firstapplet/
GoodEveningApplet.class. Also, note that the jar tool created a manifest
file. The manifest file is where any meta-information about the archive
is stored. The JAR file is saved to the FirstApplet project directory.
7 Copy GoodEvening.jar to the applets directory for testing.
After creating the JAR file, continue to “Step 8: Modifying the HTML file”
on page 10-30.

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

Deploying your applet with the Archive Builder


This is a feature of JBuilder's Archive Builder collects all the files needed to distribute your
JBuilder SE and applet and can archive them into a JAR file.
Enterprise.
To deploy your applet with JBuilder SE and Enterprise:
1 Save your project.
2 Choose Project|Make Project “FirstApplet.jpx” to compile your project.
3 Create an applets directory for your applet in your /<home>/jbproject/
directory.
This will be the testing directory where you'll put your applet HTML
file and your JAR file.

Tutorial: Building an applet 10-27


Step 7: Deploying your applet

4 Choose Wizards|Archive Builder to open the Archive Builder.

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:

9 Click Next to go to Step 3.

10-28 Introducing JBuilder


Step 7: Deploying your applet

10 Choose Include Required Classes And Known Resources.


Next, you'll manually choose the classes you want to add. Choosing
this option allows you to exclude the HTML file, which does not need
to be deployed with the classes.
11 Click the Add Classes button and select the firstapplet package. Click
OK to close the dialog box.
The package displays in the Required Classes, Packages And Resources list.

12 Click Next to go to Step 4.


13 Choose Next to continue to Step 5.
You don't need to add any libraries.
14 Accept the default settings in Step 5.
Note that the option is set to create a manifest file for the archive.
Note For information on manifest files, see “About the manifest file” in
Building Applications with JBuilder.
15 Click Finish to exit the Archive Builder.
An archive node called Applet JAR appears in the project pane. You can
modify this file by right-clicking and selecting Properties.
16 Right-click the Applet JAR archive node and choose Make to compile
your project.
The Archive Builder gathers the firstapplet package you added in Step
3 of the wizard into the JAR file.
17 Click the expand icon next to the Applet JAR archive node to see the
GoodEvening.jar archive file.

Tutorial: Building an applet 10-29


Step 8: Modifying the HTML file

18 Double-click the JAR file in the project pane.


The manifest file appears in the content pane and the contents of the
JAR file appear in the structure pane. Select a file in the structure pane
to view it in the content pane.
Note If you are delivering multiple programs to the same location, you can
deliver the redistributable files separately, rather than include them in
each of your JAR files.

See also
• “Using the Archive Builder” in Building Applications with JBuilder
• “Deploying Java programs” in Building Applications with JBuilder

Step 8: Modifying the HTML file


Now that your applet is deployed in a JAR file, you need to modify the
HTML file with the archive attribute and include the JAR file name. You'll
also add a message inside the <applet> tags that tells users without Java-
enabled browsers that they won't be able to see the applet unless they
enable Java in their browser or upgrade their browser.
To modify the HTML file,
1 Open GoodEveningApplet.html in JBuilder and add the archive attribute as
follows:
a Select the Source tab to view the HTML source code.
b Add the following HTML code inside the <applet> tag:
archive = "GoodEvening.jar"
The <applet> tag should look like this:
<applet
codebase = "."
code = "firstapplet.GoodEveningApplet.class"
archive = "GoodEvening.jar"
name = "TestApplet"
width = 400
height = 300
hspace = 0
vspace = 0
align = top
>
</applet>

10-30 Introducing JBuilder


Step 8: Modifying the HTML file

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.

Tutorial: Building an applet 10-31


Step 9: Running your deployed applet from the command line

Step 9: Running your deployed applet from the command line


It's a good idea to test the deployed applet locally before testing it on the
Web. You can do this from the command line using Sun's appletviewer.
This tells you if the web browser has everything it needs to run the applet.
If any files are missing or if there are any errors in the HTML file, the
applet won't run. You can then correct the errors before posting it on the
Web.
To run the applet at the command line,
1 Be sure copies of GoodEveningApplet.html and GoodEvening.jar are in the
applets directory.
2 Open the command-line window.
3 Clear any CLASSPATH variables to remove any class path settings for
this session as follows:
• Windows 95, 98, NT, and 2000: set CLASSPATH=
• UNIX:
• in csh shell: unsetenv CLASSPATH
• in sh shell: unset CLASSPATH
4 Change to the applets/ directory.
5 Run the appletviewer by entering the following command:
/<jbuilder>/<jdk>/bin/appletviewer GoodEveningApplet.html
Where <jbuilder> represents the version of JBuilder you're running, for
example, jbuilder6/.
Important If JBuilder is on another drive, include the drive letter.
Note For Windows, use backslashes (\).
If the “Good Evening” applet loads and runs in the appletviewer, the
deployment was successful and all the classes were found and
included. If the applet doesn't run, check the error messages, correct
them, recompile, deploy, and test again.
The “Good Evening” applet is available as a sample in the samples/
Tutorials/FirstApplet/ directory of your JBuilder installation.
If you are having problems running your applet, check the “Applet source
code” on page 10-34 at the end of the tutorial and see these topics for
common errors:
• “Solving common applet problems” at http://java.sun.com/docs/
books/tutorial/applet/problems/index.html
• “Common mistakes in the <applet> tag” and “Additional tips for
making applets work” in the Web Application Developer’s Guide.

10-32 Introducing JBuilder


Testing your deployed applet on the Web

The final step in developing your applet is to test it by running it on the


Web. This tells you if it really has all the files it needs. Although this
tutorial doesn't go into details on applet testing, see “Testing your
deployed applet on the Web” on page 10-33 for an overview of applet
testing.
Congratulations! You've created your first applet with JBuilder. Now that
you're familiar with JBuilder's development environment, you'll find its
many time-saving features make your programming easier.
For other applet tutorials, see:
• “The Java Tutorial” at http://java.sun.com/docs/books/tutorial/
index.html
• Charlie Calvert's Part II: Applets at http://homepages.borland.com/
ccalvert/JavaCourse/index.htm
• Rich Wilkman's Curmudgeon web site at http://formlessvoid.com/jc/
applets/
• John Moore's “Applet design and deployment” at http://
www.microps.com/mps/p_appletdesign.html

Testing your deployed applet on the Web


The final step in developing your applet is to run it on the Web. This tells
you if it really has all the files it needs. It's important to test your applet in
a variety of browsers to be sure that the necessary files are included in the
archive. Although this tutorial doesn't go into details on applet testing,
here are a few testing guidelines.
Complete these steps, then test your applet by running it on the Web in
various browsers:
1 Transfer the applet's HTML and JAR files to an Internet server or copy
them to a Windows NT server.
a Use an FTP (file transfer protocol) utility to transfer the files to the
server. Be sure to transfer the files as binary files.
b Verify that the HTML and JAR file locations on the server match the
codebase attribute in the HTML file and that the code attribute has the
fully qualified class name (including the package name).

Tutorial: Building an applet 10-33


Applet source code

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 source code


Applet HTML source code for GoodEveningApplet.html
<html>
<head>
<meta http="Content-Type" content="text/html; charset=windows-1252">
<title>
Good Evening HTML Page
</title>
</head>
<body>
firstapplet.GoodEveningApplet will appear below in a Java enabled browser.

<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>

10-34 Introducing JBuilder


Applet source code

Applet class source code for GoodEveningApplet.java


package firstapplet;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class GoodEveningApplet extends Applet {


boolean isStandalone = false;
BorderLayout borderLayout1 = new BorderLayout();
Panel lower = new Panel();
Panel upper = new Panel();
CardLayout cardLayout1 = new CardLayout();
Panel panel1 = new Panel();
Panel panel2 = new Panel();
Panel panel3 = new Panel();
Panel panel4 = new Panel();
Panel panel5 = new Panel();
BorderLayout borderLayout2 = new BorderLayout();
BorderLayout borderLayout3 = new BorderLayout();
BorderLayout borderLayout4 = new BorderLayout();
BorderLayout borderLayout5 = new BorderLayout();
Choice choice1 = new Choice();
Label label1 = new Label();
Label label2 = new Label();
Label label3 = new Label();
Label label4 = new Label();
Label label5 = new Label();
Label label6 = new Label();
FlowLayout flowLayout1 = new FlowLayout();
Button button1 = new Button();
/**Get a parameter value*/
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}

/**Construct the applet*/


public GoodEveningApplet() {
}
/**Initialize the applet*/
public void init() {
choice1.addItem("English");
choice1.addItem("German");
choice1.addItem("Pig Latin");
choice1.addItem("Swedish");
choice1.addItem("Australian");

try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}

Tutorial: Building an applet 10-35


Applet source code

/**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);

10-36 Introducing JBuilder


Applet source code

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));
}
}

Tutorial: Building an applet 10-37


10-38 Introducing JBuilder
Chapter

Tutorial: Using the history view


Chapter11
11
This tutorial covers the use of the history view. Version control interface is
mentioned where appropriate, but is not necessary to complete this
tutorial. You can use the history view regardless of whether you have a
version control system installed.
Terminology describing version handling varies from tool to tool. This
tutorial uses generic terms rather than tool-specific terms for the tool-
independent version handling measures available in JBuilder. For
explanations of these terms, please see the “Version handling glossary” on
page 8-1.
The history view is available in all editions of JBuilder, though the features
differ. This tutorial covers all of the features available, organized by
edition. Users of all editions of JBuilder can complete the first two lessons.
Users of SE and Enterprise can complete the first three. Users of JBuilder
Enterprise can complete all four lessons.
The changes made in this tutorial are very simple. This allows you to
focus on the history features' processes rather than on the code you
change.
We will use the Welcome project in this lesson. You will find it in the /
samples/welcome directory of your JBuilder installation. Go ahead and open
it now.
Version control users: If you want to see how the history features look when the project is under
CVS is a feature of version control, open the Welcome project, select your version control
JBuilder SE and system, and place the project under version control before you begin. As
Enterprise. Other version you use this tutorial, look for the phrase “Version control users:” on the
control integrations are a left side of the page.
feature of JBuilder
Enterprise.

Tutorial: Using the history view 11-1


Step 1: Generating multiple versions of a file

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.

Step 1: Generating multiple versions of a file


First, we need to generate several different versions of a file so that we
have something to look at in the history view.
Make sure the Welcome project is open in JBuilder.
Version control users: Make sure you have put this project under version control.
To make changes to a source file,
1 Double-click WelcomeApp.java in the project pane if it's not already open
and active in the content pane.
2 Look at the status bar in the content pane. The two numbers in the
status bar tell you the row and column of your present cursor position:

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.

11-2 Introducing JBuilder


Step 1: Generating multiple versions of a file

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.

Tutorial: Using the history view 11-3


Step 2: Using the Contents page

Step 2: Using the Contents page


The Contents page displays all the revisions of the file you have selected
in the content pane, allows you to sort the files in several ways, and
provides access to the Refresh, Revert, and Synchronize Scrolling buttons.
1 Choose the History file view tab. The Contents page appears:

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

11-4 Introducing JBuilder


Step 2: Using the Contents page

backups, version control (where applicable), and most recent saved


version:

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:

Select Edit|Copy or use the keyboard. In most keymappings, the


keyboard shortcut for copying is Ctrl + c.
9 Select the Source tab to return to the editor.
The text that shows in the editor is the same block of text that shows in
the History Content page shown above. Even if your JBuilder window
is small, you don't have to scroll down the editor to find line 31. This is
because you used the Synchronize Scrolling button.
10 In the editor, select line 31 (the boolean packFrame statement in the latest
version) and paste in the text you copied from the History Content
page. Select Edit|Copy or use the keyboard. In most keymappings, the
keyboard shortcut for pasting is Ctrl + v.
11 Save the file.

Tutorial: Using the history view 11-5


Step 3: Using the Diff page

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.”

Step 3: Using the Diff page


This is a feature of The Diff page shows you the differences between any two versions of the
JBuilder SE and active file and provides access to the Refresh button. Let's try it out.
Enterprise
1 Choose the History Diff tab.
2 Click the Rev. heading in the From area to sort the versions by revision
number.
3 Click the icon column heading in the To area to sort those revisions by
their revision management types.
You'll notice that the From area and the To area sort separately.
4 Click the Rev. heading in the To area.
Let's take a look at differences between two versions of a file.
1 Select ~2~ in the From area and Buffer in the To area.
JBuilder retrieves the differences and displays them in the source
viewer:

11-6 Introducing JBuilder


Step 4: Using the Info page

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.”

Step 4: Using the Info page


This is a feature of The Info page provides access to the comments and labels of all the
JBuilder Enterprise revisions of a file. You can sort any of its six columns. It also provides
access to the Revert and Refresh buttons.
1 Choose the Info tab.
Below the revision list you can see the label and comment for the file
version selected in the revision list.
2 Click a version to see the label and comment for that version.
3 Click on the Comment column head in the version list to sort the list by
comments.
4 Select local backup version number ~2~.

Tutorial: Using the history view 11-7


Step 4: Using the Info page

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.

11-8 Introducing JBuilder


Index
A class path 7-16
classes
adding a JDK 7-8 finding 4-17
adding libraries 7-2 ClassInsight 4-28
adding to projects 6-14 code
See also projects autocompletion 4-27
AppBrowser 4-2 automating 5-1
collapsing trees 4-16 CodeInsight 4-26
content pane 4-11 completing automatically 4-28
debugger 4-14 creating in editor 4-18
editor 4-18 drilling into 4-9
expanding trees 4-16 shortcuts 4-26
hiding panes 4-13 code symbols
menu bar 4-3 finding definition of 4-22
message pane 4-13 finding references to 4-23
moving between panes 4-16 code templates
navigating creating 4-30
AppBrowser trees 4-16 setting options 4-43
opening multiple AppBrowsers 4-2 CodeInsight 4-26
project pane 4-5 configuring 4-30
resizing content pane 4-13 display options 4-40
searching in 4-16 failure 4-27
status bars 4-15 keyboard shortcuts 4-27
structure pane 4-8 MemberInsight 4-39
toolbar 4-3 ParameterInsight 4-40
applets setting options 4-38
tutorial 10-1 color preferences
applications syntax highlighting 4-37
tutorial 9-1 comments
applying filters to packages 4-6 Javadoc documentation 4-23
assert keyword compiling
enabling 6-6 how JBuilder finds files 7-18
audio options 4-51 component palette 5-1
auto source package settings 6-6 configuring
CodeInsight 4-30
B JDKs in JBuilder 7-10
libraries 7-2
backup path 7-17 contacting Borland 1-5
Borland newsgroups 1-6
contacting 1-5 World Wide Web 1-5
Borland Online 1-5 content pane 4-11
browse path 7-16 file tabs 4-11
browser options 4-46 file view tabs 4-11
browsing classes 4-17 hiding other panes 4-13
See also Find Classes resizing 4-13
browsing symbol definitions 4-22 Contents page 8-5
copying text
C from the message pane 4-14
class files 7-15 creating project files 6-13
directory locations for 7-13 creating projects from existing files 6-8
how JBuilder finds 7-18

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

I-2 Introducing JBuilder


I K
icons keymaps 4-19
history view 8-4 customizing 4-20
IDE (integrated development environment) 4-1
IDE options 4-45 L
audio 4-51
browser 4-46 libraries
EJB Designer 4-55 adding and configuring 7-2
file types 4-48 adding to project 6-4
Run/Debug 4-51 defined 7-1
UML 4-53 display lists of 7-5
Web 4-49 editing 7-4
XML 4-50 setting paths 7-10
identifiers locating text 4-22
Find Definition command 4-22
illegal syntax notification 4-26 M
import options
Macintosh
ClassInsight 4-28
support in JBuilder 1-4
import statements 7-13
MemberInsight 4-28
Info page 8-7
display options 4-41
inserting classes
options 4-39
ClassInsight 4-28
menu bar 4-3
integrated development environment (IDE) 4-1
menus
See also IDE
commands 4-3
toolbar shortcuts 4-3
J message pane 4-13
JAR files copying text from 4-14
adding to project 7-1 multiple projects 6-17
Java files saving 6-18
directory locations for 7-12 switching between 6-17
Java language
glossaries 3-1 N
resources 3-1
naming conventions
Javadoc
packages 7-14
ToDo folder 4-8
navigating
todo tags 4-25
AppBrowser panes 4-16
Javadoc documentation
shortcut commands 4-16
comments 4-23
newsgroups 1-6
shortcuts commands 4-23
Borland 1-6
Javadoc fields
setting in Project wizard 6-6
JBuilder O
AppBrowser 4-2 object gallery 5-3
customizing the editor 4-32 wizards 5-3
customizing the IDE 4-45 online resources 1-5
JDKs opening files
configuring in JBuilder 7-10 outside of project 6-16
debugging with -classic 7-7 opening project files 6-12
editing 7-7 options
setting in the Project wizard 6-4 audio 4-51
switching and setting 7-8 browser 4-46

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

I-4 Introducing JBuilder


setting JDKs 7-8 text searches 4-22
setting paths 7-14 ToDo folder 4-8
backup 7-17 todo tags 4-25
browse path 7-16 tool tips 4-30
class path 7-16 toolbar (main window) 4-3
doc 7-17 tools
JDKs 7-6 visual design 5-1
output 7-15 trees
project paths 6-4 navigating 4-16
required libraries 7-10 searching 4-16
source files 7-15 tutorials
JDKs creating an applet 10-1
See also JDKs creating an application 9-1
setting properties using the history view 11-1
projects 7-5
shortcut commands U
coding 4-26
shortcut commands for Javadoc 4-23 UI designer 5-1
source files UML options 4-53
path 7-15 Usenet newsgroups 1-6
source pane using help 3-3
splitting view 4-21
source paths V
class files 7-13
version control
Java files 7-12
comparing files 8-1
splitter bar
viewing files 6-10
AppBrowser 4-13
viewing project files 7-18
status bars
visual design tools 5-1
AppBrowser 4-15
VM
structure pane 4-8
debugging with -classic 7-7
error messages 4-10
navigating file structure 4-8
organization 4-44 W
sorting order 4-8 Watch page 4-14
ToDo folder 4-8 Web options 4-49
using to navigate source code 4-9 Welcome Project
switching files 6-10 viewing 4-1
switching the JDK 7-8 wizards
syntax object gallery 5-3
highlighting 4-37 working directory 7-17
syntax errors
viewing and finding 4-10 X
T XML options 4-50
tabs Z
content pane 4-11
technical support 1-5 ZIP files
templates adding to project 7-1
code 4-30
project 6-2

Index I-5
I-6 Introducing JBuilder

You might also like