Sunteți pe pagina 1din 169

Introducing JBuilder ®

Borland ®
®
VERSION 8 JBuilder
Borland Software Corporation
100 Enterprise Way, Scotts Valley, CA 95066-3249
www.borland.com
Refer to the file deploy.html 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.
JBE0080WW21000introjb 3E2R1002
0203040506-9 8 7 6 5 4 3 2 1
PDF
Contents
Chapter 1 Step 4: Customizing your application’s
user interface . . . . . . . . . . . . . . . . . . 3-10
Introduction 1-1 Step 5: Adding a component to your
Chapter 2 application . . . . . . . . . . . . . . . . . . . . 3-12
Step 6: Editing your source code . . . . . . . . 3-14
Learning about JBuilder 2-1 Step 7: Compiling and running your
The JBuilder documentation set . . . . . . . . . 2-1 application . . . . . . . . . . . . . . . . . . . . 3-15
Documentation conventions . . . . . . . . . . . 2-4 Step 8: Running your application from the
Using JBuilder’s online help . . . . . . . . . . . 2-6 command line . . . . . . . . . . . . . . . . . . 3-15
How to get Help . . . . . . . . . . . . . . . . 2-6 Step 9: Adding an event to a button . . . . . . 3-16
The main parts of the Help Viewer . . . . . . 2-7 Step 10: Completing your UI . . . . . . . . . . 3-19
Using the Help Viewer. . . . . . . . . . . . . 2-7 Step 11: Preparing your application for
Using the Table of Contents . . . . . . . . 2-7 deployment . . . . . . . . . . . . . . . . . . . 3-21
Using the Index . . . . . . . . . . . . . . . 2-8 Step 12: Running your deployed
Using full-text search (including application from the command line . . . . . . 3-23
Boolean search) . . . . . . . . . . . . . . 2-8 HelloWorld source code . . . . . . . . . . . . . 3-24
Searching for text in the current topic . . 2-9 Source code for HelloWorldFrame.java . . . 3-24
Copying text from the Help Viewer . . . 2-9 Source code for HelloWorldClass.java . . . 3-27
Zooming in the Help Viewer . . . . . . . 2-9 Source code for
Using bookmarks . . . . . . . . . . . . . . 2-9 HelloWorldFrame_AboutBox.java. . . . . 3-28
Setting proxy configurations . . . . . . . 2-10
Starting the Help Viewer in a Chapter 4
separate VM . . . . . . . . . . . . . . . . 2-10
Navigating in the Help Viewer . . . . . . . . 2-11
Using the AppBrowser 4-1
Main menu. . . . . . . . . . . . . . . . . . . . . . 4-3
Using the keyboard for scrolling . . . . . 2-11
Toolbar . . . . . . . . . . . . . . . . . . . . . . . . 4-3
Viewing class reference documentation . . . 2-12
Project pane . . . . . . . . . . . . . . . . . . . . . 4-5
The layout of the reference
Creating a new project . . . . . . . . . . . . . 4-6
documentation . . . . . . . . . . . . . . 2-12
Adding files or classes to a project . . . . . . 4-6
Printing tutorials and other
Working in the project pane . . . . . . . . . . 4-6
documentation . . . . . . . . . . . . . . . . 2-12
Structure pane . . . . . . . . . . . . . . . . . . . . 4-8
Additional resources for learning about
Sorting in the structure pane . . . . . . . . . . 4-8
JBuilder . . . . . . . . . . . . . . . . . . . . . . 2-13
Viewing Javadoc information . . . . . . . . . 4-9
Developer support and resources . . . . . . . . 2-13
Navigating in the source code . . . . . . . . 4-10
Contacting Borland Technical Support. . . . 2-13
Viewing error messages . . . . . . . . . . . . . 4-11
Online resources . . . . . . . . . . . . . . . . 2-14
Content pane . . . . . . . . . . . . . . . . . . . 4-12
World Wide Web . . . . . . . . . . . . . . . . 2-14
File tabs . . . . . . . . . . . . . . . . . . . . . . 4-12
Borland newsgroups . . . . . . . . . . . . . . 2-14
File view tabs . . . . . . . . . . . . . . . . . . . 4-13
Usenet newsgroups . . . . . . . . . . . . . . 2-15
Resizing the content pane . . . . . . . . . . . . 4-13
Reporting bugs . . . . . . . . . . . . . . . . . 2-15
Message pane . . . . . . . . . . . . . . . . . . . 4-13
Chapter 3 Copying text from the message pane . . . . 4-14
Hiding and showing the message pane. . . 4-15
Tutorial: Building an application 3-1 Undocking the message pane . . . . . . . . 4-15
Step 1: Creating the project . . . . . . . . . . . . 3-2 Debugger . . . . . . . . . . . . . . . . . . . . . 4-15
Step 2: Generating your source files . . . . . . . 3-5 Status bars . . . . . . . . . . . . . . . . . . . . . 4-16
Step 3: Compiling and running your Navigating and searching in the
application . . . . . . . . . . . . . . . . . . . . 3-9 AppBrowser . . . . . . . . . . . . . . . . . . . 4-16

i
Searching trees . . . . . . . . . . . . . . . . . . . 4-17 Chapter 7
Finding classes . . . . . . . . . . . . . . . . . . . 4-18
Using Favorites. . . . . . . . . . . . . . . . . . . 4-19
JBuilder projects 7-1
Creating a new project . . . . . . . . . . . . . . . 7-1
Customizing the IDE . . . . . . . . . . . . . . . 4-19
Adding files to a project . . . . . . . . . . . . . . 7-4
Viewing a file . . . . . . . . . . . . . . . . . . . . 7-4
Chapter 5 Adding a new Java source file . . . . . . . . . . . 7-5
Working in the editor 5-1 Removing and deleting . . . . . . . . . . . . . . 7-6
Selecting a keymapping for the editor . . . . . . 5-1 Renaming projects and files . . . . . . . . . . . . 7-6
Customizing keymaps . . . . . . . . . . . . . 5-2 Opening an existing project . . . . . . . . . . . . 7-7
Splitting the source view . . . . . . . . . . . . . 5-3 Learning more about projects in JBuilder . . . . 7-7
Line numbers . . . . . . . . . . . . . . . . . . . . 5-4
Displaying line numbers . . . . . . . . . . . 5-4 Chapter 8
Going to a specific line. . . . . . . . . . . . . 5-5
Selecting text . . . . . . . . . . . . . . . . . . . . 5-5
Comparing files and versions 8-1
Version handling glossary . . . . . . . . . . . . . 8-1
Selecting an entire line . . . . . . . . . . . . . 5-5
Comparing two files . . . . . . . . . . . . . . . . 8-2
Selecting a block of line numbers. . . . . . . 5-5
Using the history view . . . . . . . . . . . . . . . 8-4
Selecting all line numbers . . . . . . . . . . . 5-5
Contents page . . . . . . . . . . . . . . . . . . 8-6
Dragging and dropping text . . . . . . . . . . . 5-6
Diff page . . . . . . . . . . . . . . . . . . . . . 8-6
Resizing the font used in the editor . . . . . . . 5-6
Info page . . . . . . . . . . . . . . . . . . . . . 8-8
Finding text in the editor . . . . . . . . . . . . . 5-6
Merge Conflicts page . . . . . . . . . . . . . . 8-9
Finding a symbol’s definition . . . . . . . . . . 5-7
Finding references to a symbol . . . . . . . . . . 5-8 Chapter 9
Formatting your code . . . . . . . . . . . . . . . 5-8
Applying formatting to your code . . . . . . 5-9 Tutorial: Building an applet 9-1
Wrapping curly braces around code Overview . . . . . . . . . . . . . . . . . . . . . . 9-2
blocks . . . . . . . . . . . . . . . . . . . . . 5-9 Good Evening applet . . . . . . . . . . . . . . 9-3
Javadoc shortcuts in the editor . . . . . . . . . . 5-10 Step 1: Creating the project . . . . . . . . . . . . 9-3
Using @todo tags in the editor . . . . . . . . 5-11 Step 2: Generating your source files . . . . . . . 9-7
Printing support in the editor . . . . . . . . . . 5-11 Step 3: Compiling and running your applet . . 9-11
Dragging a file into the editor . . . . . . . . . . 5-12 Step 4: Customizing your applet’s user
Coding shortcuts . . . . . . . . . . . . . . . . . . 5-12 interface . . . . . . . . . . . . . . . . . . . . . 9-13
CodeInsight . . . . . . . . . . . . . . . . . . . 5-12 Step 5: Adding AWT components to
MemberInsight . . . . . . . . . . . . . . . 5-14 your applet. . . . . . . . . . . . . . . . . . . . 9-17
ClassInsight . . . . . . . . . . . . . . . . . 5-14 Step 6: Editing your source code . . . . . . . . 9-20
ParameterInsight . . . . . . . . . . . . . . 5-16 Step 7: Deploying your applet . . . . . . . . . . 9-24
Find Definition (Drill Down) . . . . . . . 5-16 Deploying your applet with the jar tool . . 9-25
Tool tip expression evaluation. . . . . . . 5-16 Deploying your applet with the
ExpressionInsight . . . . . . . . . . . . . . 5-16 Archive Builder . . . . . . . . . . . . . . . 9-27
Configuring CodeInsight . . . . . . . . . 5-16 Step 8: Modifying the HTML file . . . . . . . . 9-30
Code templates . . . . . . . . . . . . . . . . . 5-17 Step 9: Running your deployed applet
Editing code templates . . . . . . . . . . . 5-17 from the command line. . . . . . . . . . . . . 9-32
Customizing the editor . . . . . . . . . . . . . . 5-18 Testing your deployed applet on the Web . . . 9-33
Applet source code . . . . . . . . . . . . . . . . 9-34
Chapter 6 Applet HTML source code for
GoodEveningApplet.html . . . . . . . . . 9-34
Automating code development 6-1 Applet class source code for
Working with the visual design tools . . . . . . 6-1
GoodEveningApplet.java. . . . . . . . . . 9-35
Using the object gallery . . . . . . . . . . . . . . 6-3
Using wizards to get a quick start . . . . . . . . 6-3

ii
Chapter 10
Tutorial: Using the history view 10-1
Step 1: Generating multiple versions of
a file . . . . . . . . . . . . . . . . . . . . . . . . 10-2
Step 2: Using the Contents page . . . . . . . . . 10-4
Step 3: Using the Diff page . . . . . . . . . . . . 10-8
Sorting revisions . . . . . . . . . . . . . . . . 10-8
Undoing changes . . . . . . . . . . . . . . . . 10-8
Using Smart Diff . . . . . . . . . . . . . . . 10-10
Step 4: Using the Info page . . . . . . . . . . . 10-11

Index I-1

iii
iv
Chapter

1
Introduction
Chapter1

Introducing JBuilder is the place to start if you are new to JBuilder. After
briefly outlining the new features of this release of JBuilder, it introduces
you to the resources that are available to you to learn about JBuilder and
quickly gets you started with a tutorial that builds your first JBuilder
application. Once you’ve had a taste of JBuilder’s development
environment, you’re ready to become more familiar with the AppBrowser
and the editor and all the coding shortcuts available to you. The various
panes of the AppBrowser are described and you’re shown how to use
them to accomplish common tasks. You’ll learn how to use JBuilder’s
editor including how to use the editor’s many coding shortcuts. You’ll
learn how to create and manage JBuilder projects. You’ll learn how to
compare files and versions with JBuilder’s history view. Finally, you’ll
have the opportunity to explore two additional basic tutorials; one that
uses the history view and another that creates an applet.
Introducing JBuilder contains the following chapters:
• Chapter 2, “Learning about JBuilder”
Describes the resources Borland provides to help you learn about
JBuilder.
• Chapter 3, “Tutorial: Building an application”
Explains how to create a simple “Hello World” application using
JBuilder.
• Chapter 4, “Using the AppBrowser”
Introduces the AppBrowser and describes how to use it.

Introduction 1-1
Introduction

• Chapter 5, “Working in the editor”


Explains how to use the many features of JBuilder’s code editor
including CodeInsight and code templates.
• Chapter 6, “Automating code development”
Describes how to generate code automatically using the visual design
tools and JBuilder’s many wizards.
• Chapter 7, “JBuilder projects”
Explains how to create a JBuilder project, describes what a JBuilder
project is, and explains how to perform basic project management
tasks.
• 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.
• Chapter 9, “Tutorial: Building an applet”
Explains how to create an AWT applet.
• Chapter 10, “Tutorial: Using the history view”
Explains the use of the history view.

1-2 Introducing JBuilder


Chapter

Learning about JBuilder


Chapter2
2
This chapter describes the resources available for learning about JBuilder.
It briefly describes JBuilder’s documentation set and explains the
conventions used within the documentation. It explains how to use
JBuilder’s online Help system; read through this section to make sure you
are making the best use of the Help system’s capabilities. The chapter also
lists other places you might go to find additional information about using
JBuilder. Finally, it gives you the information you need to contact Borland
for developer support.

The JBuilder documentation set


You have several options to access the JBuilder documentation. You can
view the documentation in JBuilder’s Help Viewer by choosing Help|
Help Topics. See “Using JBuilder’s online help” on page 2-6 for complete
information about viewing help in the Help Viewer. The documentation is
also available on your JBuilder CD in HTML format so that you can use
any web browser to view it.
If you prefer to see the documentation in printed format, you can
purchase the JBuilder manuals or download the books in PDF format for

Learning about JBuilder 2-1


The JBuilder documentation set

printing. For either option, go to the Borland JBuilder 8 documentation


web site at http://www.borland.com/techpubs/jbuilder.

Document Description
All JBuilder editions
Introducing JBuilder Tells what’s new in this version of JBuilder and
where to find the information you want in the
JBuilder documentation set. Gets you
programming quickly with a tutorial that has
you create a simple Java application using
JBuilder. Introduces JBuilder’s AppBrowser, the
code editor, and a few of the many wizards and
productive tools for quickly getting your work
done. Discusses some of the common tasks
you’ll perform again and again in managing
your programming projects. Includes
information and a tutorial on version handling
and another tutorial on creating an applet.
Getting Started with Java Provides an overview of the Java programming
language, class libraries, and editions.
Building Applications with JBuilder Discusses how to manage projects in JBuilder
and explains how JBuilder uses paths. Explains
how to compile, debug, deploy, 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 Applications with Explains how to design user interfaces and use
JBuilder layout managers. Includes step-by-step tutorials
for creating user interfaces using JBuilder’s
visual design tools.
Developing OpenTools for JBuilder Provides conceptual information about the
architecture of some of JBuilder’s subsystems
and it’s OpenTools API for building your own
add-ins.
OpenTools API Reference Provides reference documentation for the
JBuilder OpenTools API.
JDK 1.4.1 documentation API reference documentation for the Sun Java
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.
Java Language Specification Contains version 2.0 of the Java Language
Specification.
Context-sensitive online help Provides information related specifically to the
current JBuilder user interface element.

2-2 Introducing JBuilder


The JBuilder documentation set

Document Description
SE and Enterprise editions
Team Development Using JBuilder Discusses version management and explains
how to use JBuilder’s interfaces with three major
version control systems as well as JBuilder’s
own version handling tools.
Enterprise edition
Web Application Developer’s Guide Discusses the technologies used for web
development in JBuilder.
Web Services Developer’s Guide Explains how to use the JBuilder web services
features to create, browse, consume, and publish
web services.
XML Developer’s Guide Discusses the technologies used for XML
development in JBuilder.
JDataStore Developer’s Guide Explains how to make effective use of
JDataStore functionality. JDataStore is a high-
performance, small-footprint, all Java database.
Database Application Developer’s Provides information on using JBuilder’s
Guide DataExpress database functionality to develop
database applications.
DataExpress Component Library Provides detailed information online about all
Reference the JBuilder value-added, data-aware
components, classes, properties, methods, and
events.
Enterprise JavaBeans Developer’s Describes how to create Enterprise JavaBeans
Guide using JBuilder’s EJB tools and designers.

Learning about JBuilder 2-3


Documentation conventions

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

Table 2.1 Typeface and symbol conventions


Typeface Meaning
Monospaced type Monospaced type represents the following:
• text as it appears onscreen
• anything you must type, such as “Type Hello World in the
Title field of the Application wizard.”
• file names
• path names
• directory and folder names
• commands, such as SET PATH
• Java code
• Java data types, such as boolean, int, and long.
• Java identifiers, such as names of variables, classes, package
names, interfaces, components, properties, methods, and
events
• 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 are used to indicate variables in directory paths,
command options, and code samples.
For example, <filename> may be used to indicate where you need
to supply a file name (including file extension), and <username>
typically indicates that you must provide your user name.
When replacing variables in directory paths, command options,
and code samples, replace the entire variable, including the
angle brackets (< >). For example, you would replace <filename>
with the name of a file, such as employee.jds, and omit the angle
brackets.
Note: Angle brackets are used in HTML, XML, JSP, and other
tag-based files to demarcate document elements, such as <font
color=red> and <ejb-jar>. The following convention describes
how variable strings are specified within code samples that are
already using angle brackets for delimiters.

2-4 Introducing JBuilder


Documentation conventions

Table 2.1 Typeface and symbol conventions (continued)


Typeface Meaning
Italics, serif This formatting is used to indicate variable strings within code
samples that are already using angle brackets as delimiters. For
example, <url="jdbc:borland:jbuilder\\samples\\guestbook.jds">
... In code examples, an ellipsis (...) indicates code that has been
omitted from the example to save space and improve clarity. On
a button, an ellipsis indicates that the button links to a selection
dialog box.

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


description of platform conventions used in the documentation.

Table 2.2 Platform conventions


Item Meaning
Paths Directory paths in the documentation are indicated with a
forward slash (/).
For Windows platforms, use a backslash (\).
Home directory The location of the standard home directory varies by platform
and is indicated with a variable, <home>.
• For UNIX and Linux, the home directory can vary. For
example, it could be /user/<username> or /home/<username>
• For Windows NT, the home directory is C:\Winnt\Profiles\
<username>
• For Windows 2000 and XP, the home directory is
C:\Documents and Settings\<username>
Screen shots Screen shots reflect the Metal Look & Feel on various
platforms.

Learning about JBuilder 2-5


Using JBuilder’s online help

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


There are several ways to get help on all topics:
• To get help from the IDE,
• Choose Help|Help Topics from the JBuilder main menu to open the
Help Viewer.
• Click the Help button displayed on a dialog box, or press F1.
• Choose Search|Find Classes and choose a class. The class file opens
in the content pane. Click the Doc tab to see if any documentation is
available for that class.
• To get help from the AppBrowser,
• Double-click a class name in the structure pane or project pane and
select the Doc tab. Documentation for the class will be displayed.
• Select a class name in the structure pane or project pane and press
Enter, then select the Doc tab. The result is the same as double-
clicking.
• Put the cursor on a Java keyword in the editor and press F1 to get
help for that keyword.
• To get help from the Inspector, choose a property or event and press F1.
• To get help from your web browser, follow these steps:
a Unjar all of the .jar files in your JBuilder doc directory. To do so, use
your favorite tool, such as WinZip, or, from the command line, go to
the doc directory and enter the following for each JAR file: ../<jdk>/
bin/jar xf <docjarfile.jar>.
b After all of the JAR files have been unarchived, open index.html with
your browser and follow the directions.
Note There is no full-text search capability across the online documentation
set when you access it from your web browser.

2-6 Introducing JBuilder


Using JBuilder’s online help

The main parts of the Help Viewer


The JBuilder Help Viewer includes the following:
• The main menu.
• The Contents page, which displays an expandable Table of Contents for
all books.
• The Index page, which shows the index entries for all books.
• The Find page, which allows you to enter search words for all books.
• The content pane, which displays the text of the selected topic.
• The following buttons:

Button Name Description


Home Goes to the first topic in the history list.

Back Goes to the previous topic in the history list.

Forward Goes to the next topic in the history list.

Print Prints the current topic.

Find Finds text in the current topic.

Using the Help Viewer


Using the Table of Contents
To choose a topic from the Table of Contents,
1 Click the Contents tab in the top left of the Help Viewer.
2 Double-click a book icon to expand the topics in that book.
3 Click an item in the Table of Contents to view the topic in the content
pane.

Learning about JBuilder 2-7


Using JBuilder’s online help

Using the Index


To look up a topic in the Index,
1 Click the Index tab in the top left of the Help Viewer.
2 Type the topic in the text field.
As you start typing, the index scrolls, doing an incremental search on
the index entries to find the closest match.
3 Double-click the highlighted index topic or press Enter to view the
content.
If there is more than one topic for the selected index entry, the Index
pane splits in two and displays a topic list in the lower portion of the
pane. Click the topic you want to display.

Using full-text search (including Boolean search)


To find text in all books and use the Boolean search,
1 Click the Find tab in the top left of the Help Viewer.
2 Type the search words in the text field.
As you type, the search scrolls to find the closest match.
The Help Viewer supports the following Boolean search operations (Do
not use quotes in the text field.):
• Intersection of topics (AND):
Type a plus sign (+) between the words to find all topics that include
all of the words.
• Union of topics (OR):
Insert a comma (,) between the words to find all topics that include
at least one of the words.
3 Double-click the highlighted topic or press Enter to view the content.
If there is more than one topic for the selected entry, the Find pane
splits in two and displays a topic list in the lower portion of the pane.
Click the topic you want to display.
Tip Full-text search returns results from all of the text in all of the topics
available in the online documentation. If you find that it returns too many
results, try using the Index tab instead.

2-8 Introducing JBuilder


Using JBuilder’s online help

Searching for text in the current topic


To find text in the current topic of the Help Viewer,
1 Click the Find button in the Help Viewer or press Ctrl + f.
2 Type the search words in the Find Text in Current Topic dialog.
3 Click Find Next or press Enter to continue the search.
4 Click Cancel to close the dialog box.
5 Press F3 to search again without opening the dialog box.

Copying text from the Help Viewer


To copy text from the Help Viewer,
1 Select the text in the content pane.
2 Select Edit|Copy from the Help Viewer main menu or press Ctrl + c.

Zooming in the Help Viewer


You can change the apparent size of the font and images in the Help
Viewer by zooming in and out. This way you can examine images more
closely, fit more text at once into the view window, or otherwise adjust the
viewing size for your comfort. The zoom increments are small, so you can
control the apparent size of the view precisely.
There are two ways to perform each type of zoom:
To zoom in,
• Press Ctrl + u; hold down Ctrl and press u again until the view is the size
you want.
• Select Options|Zoom In.
To zoom out,
• Press Ctrl + d; hold down Ctrl and press d again until the view is the size
you want.
• Select Options|Zoom Out.
To return to normal view, Select Options|Zoom Normal.

Using bookmarks
To add a bookmark for the current page in the Help Viewer, select
Bookmarks|Add Bookmark from the main menu.
To edit bookmarks in the Help Viewer,
1 Select Bookmarks|Edit Bookmarks from the main menu. The
Bookmark Editor dialog box opens.

Learning about JBuilder 2-9


Using JBuilder’s online help

2 Select the bookmark and click the option to remove, rearrange, or go to


bookmark.
3 Click Close.
To go to a bookmark, select Bookmarks and choose a bookmark from the
list. The first ten bookmarks have mnemonics in the Bookmarks menu, so
you want the most commonly used bookmarks at the top of the list. You
are limited to 25 bookmarks on the menu, although you can edit the
help.properties file to increase this number. The help.properties file is
created the first time you exit the Help Viewer and is saved to the
<.jbuilder> directory in your home directory.

Setting proxy configurations


To access internet sites from the Help Viewer through a proxy server, you
must specify the host ID and port number for your proxy server. These
values are set within the Help Viewer.
To enable the Help Viewer to use a proxy server to connect to the internet,
1 Open the Help Viewer (Help|Help Topics).
2 Choose Options|More to open the Help System Options dialog box.
3 Check the Connect to the Internet Via Proxy Server option.
4 In the Host field, enter the name or numeric IP address of the proxy
server.
5 In the Port field, enter the proxy server’s port number.
6 Click OK.
7 Restart JBuilder for the change to take effect.

Starting the Help Viewer in a separate VM


You can run the Help Viewer in a separate virtual machine (VM) to
provide access to tutorials and other help topics while a modal dialog is
being displayed. This option is set from within the Help Viewer.
To configure the Help Viewer to start in a separate VM,
1 Open the Help Viewer (Help|Help Topics).
2 Choose Options|More to open the Help System Options dialog box.
3 Check the Start Help System in Different VM option.
4 Click OK.
5 Restart JBuilder for the change to take effect.

2-10 Introducing JBuilder


Using JBuilder’s online help

Navigating in the Help Viewer


The following table describes how to move around in the Help Viewer:

To Do this... Keyboard shortcuts


Change books or go to a Click the topic title. Use the arrow keys.
topic
Expand or collapse a Click the icon beside a Select the book and press
section of the Table of topic on the Contents page Enter to open.
Contents or double-click the topic. You can also select the
book and use the right
arrow and left arrow keys
to open and close the
book.
Return to the previous Click the Back Ctrl+Left Arrow
topic in the history list button.
Go to the next topic in the Click the Forward Ctrl+Right Arrow
history list button.
Go to the first topic in the Click the Home Ctrl+Home
history list button.
Find (search for) text in Click the Find Ctrl+F
the current topic button.
Search again F3
Find (search for) text in all Click the Find tab.
books
Follow a hypertext link Click the link in the text.
underlined in the text

Using the keyboard for scrolling


When you select an entry in the Contents, Index or Find pages of the Help
Viewer, the keyboard focus stays there. Navigation keys (such as
PageDown) continue to scroll the left side of the Help Viewer rather than
the content pane on the right side.
To shift focus to the content pane on the right side of the Help Viewer,
press the Tab key. The Tab key cycles from the pane selected in the left
side of the Help Viewer (Contents, Index, or Find) to the content pane and
then to the navigation buttons. Press Shift+Tab to go back.

Learning about JBuilder 2-11


Using JBuilder’s online help

Viewing class reference documentation


You can view reference documentation for a class in the AppBrowser, the
Help Viewer, or a web browser.
To display reference documentation in the AppBrowser, do one of the
following:
• Double-click a class name in the structure pane or project pane to
display source code for that class in the source pane. Select the Doc tab
to view the documentation for that class.
• Choose Search|Find Classes, and choose a class. Select the Doc tab to
see the documentation for that class.
For the class documentation to be found, the import statements at the top
of your source file must point to the desired class or package. If the
message Java Symbol Not Found is displayed, navigate to a source file that
imports the desired class.
To display reference guides in the Help Viewer, do one of the following:
• In the Shortcuts page of the Help Viewer, click a reference book.
• In the JBuilder main window, choose Help and the desired reference
guide.
• In the Contents page of the Help Viewer, choose a reference book.

The layout of the reference documentation


The documentation in the DataExpress Component Library Reference is
delivered in standard Javadoc format. For information on using the
Javadoc format, see “How This API Document Is Organized” in
DataExpress Component Library Reference.

Printing tutorials and other documentation


To print tutorials and other JBuilder documentation, open the
documentation in the Help Viewer and select File|Print. Documentation
is also available in PDF format on the JBuilder web site at
http://www.borland.com/techpubs/jbuilder/.
For a list of tutorials and their PDF file names, see Help|JBuilder
Tutorials.

2-12 Introducing JBuilder


Additional resources for learning about JBuilder

Additional resources for learning about JBuilder


For more information about JBuilder, see these options:
• Visit the JBuilder web site at http://www.borland.com/jbuilder/ and the
Borland Community web site at http://community.borland.com/.
• Take an introductory tour of JBuilder by opening the Welcome Project.
Choose Help|Welcome from the JBuilder main menu.
• Check the Release Notes (Help|Release Notes) to find information
about the latest JBuilder updates and known problems with suggested
workarounds.

Developer support and resources


Borland provides a variety of support options and information resources
to help developers get the most out of their Borland products. These
options include a range of Borland Technical Support programs, as well as
free services on the Internet, where you can search our extensive
information base and connect with other users of Borland products.

Contacting Borland Technical Support


Borland offers several support programs for customers and prospective
customers. You can choose from several categories of support, ranging
from free 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.

Learning about JBuilder 2-13


Developer support and resources

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

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


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

World Wide Web


Check www.borland.com/jbuilder regularly. This is where the Java Products
Development 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)
• 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. The Borland newsgroups provide a means for
the global community of Borland customers to exchange tips and
techniques about Borland products and related tools and technologies.
You can find user-supported newsgroups for JBuilder and other Borland
products at http://www.borland.com/newsgroups/.

2-14 Introducing JBuilder


Developer support and resources

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) for the
JBuilder documentation team, you may email jpgpubs@borland.com. 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.

Learning about JBuilder 2-15


2-16 Introducing JBuilder
Chapter

Tutorial: Building an application


Chapter3
3
Many developers prefer to learn by doing. If this is you, follow the steps
outlined in this tutorial to learn about using JBuilder’s integrated
development environment (IDE) to create applications. 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
Enterprise
• Run the deployed application from the command line.

Tutorial: Building an application 3-1


Step 1: Creating the project

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

If you need specific information about the IDE or editor as you work
through the tutorial, see Chapter 4, “Using the AppBrowser,” and
Chapter 5, “Working in the editor.”
See the Tutorials section in the JBuilder Quick Tips for useful information
about viewing and printing tutorials. The Accessibility options section in
the JBuilder Quick Tips contains tips on using JBuilder features to
improve JBuilder’s ease of use for people with disabilities.
For information on documentation conventions used in this tutorial and
other JBuilder documentation, see “Documentation conventions” on
page 2-4.

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 2-4, and for more information on projects, see Chapter 7,
“JBuilder projects.”

3-2 Introducing JBuilder


Step 1: Creating the project

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.
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
“Managing paths” in Building Applications with JBuilder.

Tutorial: Building an application 3-3


Step 1: Creating the project

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

6 Click Next to go to Step 3 of the wizard.


7 Make the following changes in the appropriate fields of Step 3:
a Accept the Encoding and Automatic Source Packages defaults. The
Automatic Source Packages option is a feature of JBuilder SE and
Enterprise.
b Type Hello World in the Title field of the class Javadoc fields.
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.

3-4 Introducing JBuilder


Step 2: Generating your source files

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

Step 2: Generating your source files


The Application wizard creates .java source files that are added to the
project you just created.

Tutorial: Building an application 3-5


Step 2: Generating your source files

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 Type in 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.

3-6 Introducing JBuilder


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:

Tutorial: Building an application 3-7


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 The message pane appears only when a message is displayed.
Therefore, you won’t see the message pane yet if you are following
these steps.
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 3.1 AppBrowser elements

3-8 Introducing JBuilder


Step 3: Compiling and running your application

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.

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 on the JBuilder
toolbar 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 Click the Close button on the the HelloWorldClass tab in the message
pane close any messages.

Tutorial: Building an application 3-9


Step 4: Customizing your application’s user interface

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.
Figure 3.2 UI designer elements

3-10 Introducing JBuilder


Step 4: Customizing your application’s user interface

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.
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 Click the ellipsis button to access the Border dialog box.

Tutorial: Building an application 3-11


Step 5: Adding a component to your application

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.
No layout, or null, 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 deployment. Later in the tutorial, you’ll switch to an appropriate
portable layout for your design before deploying it.
Note The message pane appears only when a message is displayed.
Therefore, you won’t see the message pane yet if you are following
these steps.
8 Choose File|Save All or click the Save All icon on the toolbar 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 the UI designer, which is filled with the jPanel1 component.
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 try
again.

3-12 Introducing JBuilder


Step 5: Adding a component to your application

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.
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 or click the Save All icon on the toolbar to save
the project.

Tutorial: Building an application 3-13


Step 6: Editing your source code

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

3-14 Introducing JBuilder


Step 7: Compiling and running your application

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

Tutorial: Building an application 3-15


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.

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.
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-16 Introducing JBuilder


Step 9: Adding an event to a button

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.

Tutorial: Building an application 3-17


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.

3-18 Introducing JBuilder


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.

Tutorial: Building an application 3-19


Step 10: Completing your UI

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


Steps 11 and 12 use features found in JBuilder SE and Enterprise. If you
are using JBuilder Personal, you have completed the tutorial.

3-20 Introducing JBuilder


Step 11: Preparing your application for deployment

Step 11: Preparing your application for deployment


Continue with the tutorial The Archive Builder collects all the files needed to distribute your
if you have JBuilder SE or program and can archive them into a Java archive file (JAR file).
Enterprise
To deploy your application:
1 Choose Wizards|Archive Builder to open the Archive Builder.
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.

Tutorial: Building an application 3-21


Step 11: Preparing your application for deployment

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

3-22 Introducing JBuilder


Step 12: Running your deployed application from the command line

Step 12: Running your deployed application from the


command line
To test the deployed application, you can run the JAR file 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.
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 Applications with
JBuilder.

Tutorial: Building an application 3-23


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

3-24 Introducing JBuilder


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

Tutorial: Building an application 3-25


HelloWorld source code

jMenuHelp.add(jMenuHelpAbout);
jMenuBar1.add(jMenuFile);
jMenuBar1.add(jMenuHelp);
this.setJMenuBar(jMenuBar1);
contentPane.add(jToolBar, BorderLayout.NORTH);
contentPane.add(statusBar, BorderLayout.SOUTH);
contentPane.add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jLabel1, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(45, 125,
102, 110), 10, -6));
jPanel1.add(jButton4, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(46,
148,
0, 149), 16, 0));
}
/**File | Exit action performed*/
public void jMenuFileExit_actionPerformed(ActionEvent e) {
System.exit(0);
}
/**Help | About action performed*/
public void jMenuHelpAbout_actionPerformed(ActionEvent e) {
HelloWorldFrame_AboutBox dlg = new HelloWorldFrame_AboutBox(this);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height -
dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.show();
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
jMenuFileExit_actionPerformed(null);
}
}

void jButton4_actionPerformed(ActionEvent e) {
jLabel1.setForeground(new Color(255,0,0));
}
}

3-26 Introducing JBuilder


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

Tutorial: Building an application 3-27


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();
}
/**Component initialization*/
private void jbInit() throws Exception {

3-28 Introducing JBuilder


HelloWorld source code

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

Tutorial: Building an application 3-29


3-30 Introducing JBuilder
Chapter

Using the AppBrowser


Chapter4
4
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.

Using the AppBrowser 4-1


Using the AppBrowser

Figure 4.1 The AppBrowser window

You can open multiple AppBrowsers by selecting Window|New


Browser. In JBuilder SE and Enterprise, you can also right-click a file in the
project pane and choose Open In New Browser.
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.

4-2 Introducing JBuilder


Main menu

Main menu
The main menu is at the top of the AppBrowser. The Team menu is a
feature of JBuilder SE and Enterprise. For an explanation of each menu,
see “JBuilder menus” in the online help.

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 online help.
edition
The toolbar shown here is wrapped; it probably will look slightly different
on your monitor depending on the width of your AppBrowser window.

The toolbar provides shortcut buttons for the following menu commands:

Table 4.1 Toolbar buttons


Menu
Icon 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.

File|Save All Saves all open projects and files, using the current
names.

Using the AppBrowser 4-3


Toolbar

Table 4.1 Toolbar buttons (continued)


Menu
Icon equivalent Description
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 Runs your application using the default


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

4-4 Introducing JBuilder


Project pane

Table 4.1 Toolbar buttons (continued)


Menu
Icon equivalent Description
Run|Optimize Evaluates the project’s code using Optimizeit. This is
Project only available when you have Optimizeit installed.
View|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.
View|Back Takes you back to the previous item in the history
list.
View|Forward Takes you forward to the next item in the history list.

Help|Help Opens the help viewer.


Topics

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, and should not be 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 icon: 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.

Using the AppBrowser 4-5


Project pane

Creating a new project


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 double-click the Project icon. To create a new
project that uses existing code and resources, choose the Project For
Existing Code icon from this same page.

Adding files or classes to a project


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 class source file, choose File|New Class to open the
Class wizard; the class you create is placed in the current project.
To add an empty file to your project, choose File|New File to display the
Create New File dialog box Specify the name of your file in the Name field
and select the file type from the Type drop-down list. You can also use the
Directory field to change where the new file is saved. When you choose
OK, the new empty file is added to your project.
If you use the Application wizard, which you’ll find on the General page
of the object gallery, the new application is added to the current project.

Working in the project pane


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. To open a
file and display it in the AppBrowser content pane, select it in the project
pane and press Enter or double-click it.

4-6 Introducing JBuilder


Project pane

Figure 4.2 Project pane context menu

The options you find on the project pane menu depend on your context
and the version of JBuilder you are using.
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.
Tip You can quickly 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 7, “JBuilder projects” and “Creating and managing projects” in
Building Applications with JBuilder for more information on projects.
• “Searching trees” on page 4-17 to learn more about searching in the
project tree.
• “Filtering packages” in Building Applications with JBuilder to learn about
how you can filter which packages you see in the project pane.
To learn more about working with projects, see “Creating and managing
projects” in Building Applications with JBuilder.

Using the AppBrowser 4-7


Structure pane

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, an Imports
folder containing a list of imported packages, and a To Do folder that
contains Javadoc @todo tag comments.
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-17.

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.
Figure 4.3 Structure view properties

4-8 Introducing JBuilder


Structure pane

These options are also available on the Java Structure page of the Editor
Options dialog box (Tools|Editor Options). You can also click the Help
button in the Editor Options dialog box.

Viewing Javadoc information


Javadoc @todo tags in Javadoc comments also display in the structure pane
in a To Do folder. Javadoc conflicts are displayed in a Javadoc Conflicts
folder.

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

Using the AppBrowser 4-9


Structure pane

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.
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 the file you were viewing, click the Home
button on the main toolbar.

4-10 Introducing JBuilder


Viewing error messages

Viewing error messages


Syntax errors are underlined in the editor. Put your cursor on 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
corresponding line of code is highlighted in the editor.

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

Using the AppBrowser 4-11


Content pane

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 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 that 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. Click
the dialog box’s Help button for information about these options.

4-12 Introducing JBuilder


File view tabs

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:
Source, Design, Bean, UML, Doc, and History. The tabs available vary by
JBuilder edition.

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” in the online help for other pane configurations.

Message pane
At times a tabbed message pane appears at the bottom of the AppBrowser
for displaying user messages from different operations, such as:
• Building and compiling
• Running
• Debugging
• Searching
• Refactoring code
• Unit testing
• Version control
JBuilder generates a new tab at the bottom of the message pane for each
new process. These tabs allow you to interact with the running process.
An icon on the tab indicates that a process is active and console output is
possible through the message pane text area.

Using the AppBrowser 4-13


Message pane

Here’s an example of the AppBrowser with a message pane at the bottom


reporting a syntax error:

A Build tab displays during compile if there are errors or warnings.


Some operations 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 operations simultaneously on the same project
or different projects. A separate message tab is created for each new
operation started with the main toolbar Run and Debug buttons.
To start a new run or debug operation, 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 operation.
During some operations, such as running, debugging, version control, and
refactoring, the message pane contains a status bar to advise you of the
operation or result of the current process.

Copying text from the message pane


You can also copy from the message pane. Right-click the message pane
and choose Copy All or select the text you want to copy and choose Copy
Selected Content.

4-14 Introducing JBuilder


Debugger

Hiding and showing the message pane


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.

Undocking the message pane


If you prefer, you can undock the message pane so it becomes a
free-floating window that you can position on your screen as you like.
To undock the message pane, click the icon at the lower-right corner of the
message pane.
To attach the message pane to the bottom of the AppBrowser again, click
the icon at the lower-right corner of the free-floating message pane.

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 these features:
• 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.
• 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.

Using the AppBrowser 4-15


Status bars

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 operations 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),
the insertion mode, and the keybinding mode in a text file or the size of an
image file. A text file also contains a magnifying glass tool you can use to
change the fonts size used in the editor.

The message status bar is displayed at the bottom of the message pane
during such processes as running, debugging, and version control.

Navigating and searching in the AppBrowser


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

Table 4.2 Navigation keyboard shortcuts


Keyboard shortcut Action
Tab Moves forward in rotation order to the next AppBrowser
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.

4-16 Introducing JBuilder


Searching trees

Table 4.2 Navigation keyboard shortcuts (continued)


Keyboard shortcut Action
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 here, entering
texteditframe.jb in the structure pane selects the first jButton component in
the TextEditFrame branch.

Normally, entries beginning with the specified text are selected. Use
wildcard characters to expand the search:
• An asterisk matches any string of characters.
• A question mark matches any single character.

Using the AppBrowser 4-17


Finding classes

Finding classes
Press Ctrl+-(minus) to invoke the Find Classes dialog box. 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 box 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 box closes and the class opens and becomes the active file in
the editor.
Both pages support the wildcards * and ?.

4-18 Introducing JBuilder


Using Favorites

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 operating system. For instance, if you’re
using Windows, they’re in a pane on the left of the dialog box; if you’re
using the Macintosh, they’re on a navigation bar. Select a Favorite to put
the dialog box selection in that directory.
JBuilder defines default links, but 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.

Customizing the IDE


You have many options to customize how the IDE appears and behaves.
For example, you can choose the look and feel for the AppBrowser, select
or customize the keymap that determines the keystrokes you use to access
the IDE, and specify how the tabs on the files in the content pane appear.
There are additional options for specific parts of the IDE, such as the
Run/Debug or UML. All of these options are available from the IDE
Options dialog box.

Using the AppBrowser 4-19


Customizing the IDE

To access the IDE Options dialog box, choose Tools|IDE Options.

To learn about using the many available options in the IDE Options dialog
box, click the Help button.
To customize the editor, choose Tools|Editor Options.

Click Help to read information about using the editor options.

4-20 Introducing JBuilder


Chapter

Working in the editor


Chapter5
5
JBuilder has a superb code editor that has many features to make the task
of writing code quicker and easier.
To open a file in the editor, either double-click a text-based file 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.
The editor offers a variety of productivity features, such as brace
matching, keyboard shortcuts, syntax highlighting, customizable 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 or click the editor and
press Shift+F10 to display the context menu.

Selecting a keymapping for the editor


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.

Working in the editor 5-1


Selecting a keymapping for the editor

Because different programmers have different habits and preferences,


JBuilder provides a number of editor emulations. Choose the one that
you’re most comfortable with:
• BRIEF
• CUA
• Emacs
• Macintosh
• Macintosh CodeWarrior
• Visual Studio
When you first install JBuilder for Windows, Linux, or Solaris, the CUA
keymapping will be in effect. If you install JBuilder for the Macintosh, the
Macintosh keymapping will be in effect.
To select a different keymapping scheme for the editor,
1 Click the drop-down arrow just to the left of the magnifying glass at the
right side of the status bar.
2 Choose the keymapping scheme of your choice.
You can also use either the IDE Options or Editor Options dialog box to
change the keymapping scheme.
1 Choose Tools|IDE Options and select the Browser page, or choose
Tools|Editor Options and select the Editor page.
2 Click the Keymap field and select the editor emulation you want from
the drop-down menu.
3 Choose OK.
The new keymap emulation is active immediately.

Customizing keymaps
If you have JBuilder SE or Enterprise, you can customize the selected
keymapping using the Keymap Editor. In JBuilder Personal, the Keymap
Editor is read-only and you can’t change keymappings.
To access the Keymap Editor,
1 Choose Tools|IDE Options and select the Browser page or choose
Tools|Editor Options and select the Editor page.

5-2 Introducing JBuilder


Splitting the source view

2 Click the Customize button next to the Keymap field.


3 Click 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.
5 Click the table headers to change the sort order.
Figure 5.1 CUA Keymap Editor

For more information about using the Keymap Editor, click its Help
button.

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 the Source pane and choose either Split
Vertically or Split Horizontally. To return a split view to one pane,
right-click in each pane and choose Close View.

Working in the editor 5-3


Line numbers

Line numbers
The editor has an option to display line numbers in the left gutter margin.

This feature can be turned on and off with the Line Numbering option on
the Editor page of the Editor Options dialog box (Tools|Editor Options).
It is also possible to instantly move the cursor to a specific line number by
choosing Search|Go To Line, and entering the line number. Both of these
features are accessible from shortcuts on the status bar.

Displaying line numbers


You can quickly control line numbering from the status area at the bottom
of the editor. The line number and column number for the location of the
cursor is always displayed on the status bar. To the right of this display is
a drop-down arrow.

To show line numbers, click the drop-down arrow and select Show Line
Numbers. To hide them, click the drop-down arrow and uncheck Show
Line Numbers.

5-4 Introducing JBuilder


Selecting text

Going to a specific line


To go to a specific line number, click on the line/column number display
itself, or click the down-arrow beside it and choose Go To Line to bring up
the Go To Line Number dialog box and enter the number of the line.

Alternatively you can press Ctrl+G to bring up the Go To Line dialog box.

Selecting text
There are a variety of ways to select text in the editor. Use the mouse to
select a section of text, or place the cursor at the starting location, then
while holding down the Shift key, click the left mouse button at the end of
the selection area. You can also use Ctrl+Shift with the arrow keys to
highlight words and lines quickly.
In addition to these, there are shortcuts in the editor for quickly selecting
entire lines of text using the line number display in the gutter margin.
Note To use these shortcuts, make sure line numbers are displayed in the gutter
margin (see “Displaying line numbers” on page 5-4.)

Selecting an entire line


Click on a line number to select that entire line.

Selecting a block of line numbers


You can select a contiguous block of lines without having to scroll. Click
the first line number in the gutter margin, hold the Shift key down and
click the last line number.

Selecting all line numbers


To quickly select all the lines in the entire file, place the cursor in the
gutter over any line number and press Ctrl and click on the line number
with the mouse.

Working in the editor 5-5


Dragging and dropping text

Dragging and dropping text


You can drag and drop selected text in the editor. Highlight the desired
text then drag it with the mouse to the new location. If you are moving an
entire line of text, and the Smart Paste option is selected in the Editor
Options, the line will be automatically indented for you when you drop it
on the new line.

Resizing the font used in the editor


You can quickly resize your code font in the editor.
To enlarge the font size of your code, click the magnifying glass icon at the
right side of the status bar of the editor. Each time you click the icon, your
text grows larger. You can also increase the font size by clicking the
pull-down arrow next to the magnifying glass icon and choosing Zoom In.
To decrease the size of your code, click the pull-down arrow next to the
magnifying glass icon and choose Zoom Out.
To return the size of the text in the editor to its default size, click the
pull-down arrow next to the magnifying glass icon and choose Normal.
You can also change both the font and its size using the Tools|Editor
Options dialog. Click the Display tab and make your changes and use the
Editor Font options on that page. Click the Help button in the dialog box if
you need more information.
For information about changing the size of the font used by the entire IDE
including the editor, choose Tools|IDE Options and click the Help button
to read about the Font Size Increase option on the Browser page of this
dialog box.

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 5.1 Commands for finding text


Task Command
Find text Search|Find
Search for text across all files in the selected Search|Find in Path
path(s)
Find text and replace it with new string Search|Replace

5-6 Introducing JBuilder


Finding a symbol’s definition

Table 5.1 Commands for finding text (continued)


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

The Find dialog box and the Replace dialog box both provide the option to
replace text. Other options in these dialog boxes include case-sensitive
searching, the use of wildcards or regular expressions, and defining the
extent of the search/replace task. Click Help in these dialog boxes to learn
about using about these options.

Finding a symbol’s definition


This is a feature of The Find Definition command, available on both the editor’s context
JBuilder SE and menu and the Search menu, allows you to navigate from the usage of a
Enterprise symbol to its definition. Before you can find a symbol’s definition, you
must have compiled your project and the class that contains the definition
must be on the import path
To see how a symbol is defined, right-click the symbol you want to see
defined and choose Find Definition.
1 Position the cursor in the editor on the symbol you want to see defined.
2 Right-click the symbol 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.

Working in the editor 5-7


Finding references to a symbol

Finding references to a symbol


This is a feature of The Find References command, available on the editor’s context menu
JBuilder SE and and the Search menu, allows you to discover all source files that use a
Enterprise given symbol.
To find all references to a symbol, right-click the symbol and choose Find
References.
To discover the source file(s) where the reference exists, expand a category
node and traverse the hierarchy tree in the message pane. Double-click a
reference to open the source file and to position the cursor directly on the
reference in the file.
Important To find references to your selected symbol, you must have already
compiled your project. For more information, see “Setting up for
references discovery and refactoring” in Building Applications with JBuilder.

Formatting your code


You now have the ability to specify your formatting preferences and
automatically format your source code. To access these settings, choose
Project|Project Properties and click the Formatting tab.

5-8 Introducing JBuilder


Formatting your code

The tabs on this page allow you to customize your code formatting by
specifying the following types of preferences:
• Indenting
• Tab size
• End of line characters
• Multi-line parameters
• Continuation indent
• Braces
• Spaces
• Blank lines
• Text wrapping
• Event handling
• Import statements and their order
On each page is a Preview window that displays what the selected
preference will look like.

Applying formatting to your code


To apply the formatting to your code, open a file in the editor and choose
Edit|Format, or press the Tab key.
Important Formatting properties apply to all files in a project.
You can also export your code formatting preferences, or import
previously saved preferences using the Import and Export buttons at the
bottom of the Formatting tab in the Project Properties dialog box.
For details on setting code formatting options, press the Help button at the
bottom of the Formatting page of the Project Properties dialog box.

Wrapping curly braces around code blocks


To quickly wrap a block of code in curly braces, place an open curly brace
at the beginning of the block, move to the end of the block and press Enter.

Working in the editor 5-9


Javadoc shortcuts in the editor

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
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 that activated when you type /** and press
Enter. 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.

5-10 Introducing JBuilder


Printing support in the editor

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.

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 JBuilder SE and Enterprise: These @todo tags appear in
JBuilder’s structure pane in a To Do folder.
JBuilder’s code templates make adding @todo tags to your code very easy.
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.

Working in the editor 5-11


Dragging a file into the editor

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

Dragging a file into the editor


You can use drag and drop to bring an external file from outside JBuilder
into the editor. The file must be a type that JBuilder recognizes. The file is
opened in the editor, but not added to the project. If you want the file
added to your project, add it using the Add Files/Packages button at the
top of the project pane or right-click the project file in the project pane and
choose Add Files/Packages. The drag and drop feature is an option that
can be turned off in the Editor Options dialog box.

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.

5-12 Introducing JBuilder


Coding shortcuts

This is a feature of JBuilder • Find Definition: drills down to source code for current variable,
SE and Enterprise 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.
Important The project must be compiled before imported classes are available to
CodeInsight.
Figure 5.2 CodeInsight pop-up window

Invoke the CodeInsight tool, select the symbol you want to insert, and
press Enter.
To access CodeInsight, use these keyboard shortcuts:

Table 5.3 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.
ClassInsight Ctrl+Alt+Space Inserts a class name into a writable file. JBuilder
Ctrl+Alt+H 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.

Working in the editor 5-13


Coding shortcuts

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.

See also
• Help|Keyboard Mappings.
• “Customizing the editor” on page 5-18.
• “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

5-14 Introducing JBuilder


Coding shortcuts

to navigate the list. To find classes in any libraries, the libraries must be in
your project. When you add a class using ClassInsight, the import
statement is automatically added as the last import statement in your
code. To reorder and optimize your import statements, use Optimize
Imports in the editor. See “Optimize Imports” in Building Applications with
JBuilder.
Important If you’ve added a source file or library to your project, you must
recompile the project and press the Refresh button in the project pane
before ClassInsight can recognize the additions. Use Project|Make Project
or Project|Rebuild Project to recompile.

See also
• “Optimize Imports” in Building Applications with JBuilder.
• “Adding and configuring libraries” in Building Applications with
JBuilder.
• “Class path” in Building Applications with JBuilder.

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

Working in the editor 5-15


Coding shortcuts

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


This is a feature of Find Definition quickly takes you to the source code for the current
JBuilder SE and variable, method, or class name in the editor if it exists. If it’s not available,
Enterprise 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.
To display the ExpressionInsight window,
• Hold down the Ctrl key (the Command key on Macintosh) and move the
mouse over your code in the editor. The ExpressionInsight window
displays when the mouse passes over a meaningful expression.
• Move your mouse to the expression you want to see in more detail and
press Ctrl plus the right mouse button.

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|

5-16 Introducing JBuilder


Coding shortcuts

CodeInsight. For more information, click the Help button on the


CodeInsight page of the dialog box.
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 To use a code template in your code, select one of these methods:
in JBuilder Personal. • 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 5-12.
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.

Working in the editor 5-17


Customizing the editor

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.
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, click the Help button on the Templates page of the
Editor Options dialog box.

Customizing the editor


You can customize how the editor appears and works in many ways. For
example, you can change the font and font size used in the editor, enable
or disable line numbering, specify your favorite colors for editor elements,
determine how you want elements in the structure pane to appear,
customize how common keystrokes behave, and much more. You can also
specify how you want various CodeInsight features to work and you can
edit and even create your own code templates.
You customize the editor using the Editor Options dialog box. To access
the dialog box, choose Tools|Editor Options. For complete information
about all the options available to you, click the Help button on the various
pages of the Editor Options dialog box. You can also read about
customizing the editor by choosing Help|JBuilder Environment and
selecting the “Customizing the editor” topic.

5-18 Introducing JBuilder


Chapter

Automating code development


Chapter6
6
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 6-1


Working with the visual design tools

Figure 6.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.
You use the UI Designer to build user interfaces that contain visual
elements, such as list boxes and buttons. 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.
For information about using the UI designer, see “Introducing the
designer” in Designing Applications with JBuilder.

6-2 Introducing JBuilder


Using the object gallery

The menu designer is used to create menus. Menu components appear in


the Menu folder of the component tree. To access the menu designer,
right-click the Menu folder or one of the components it contains, if any,
and choose Activate Designer.
For information about using the menu designer, see “Designing menus”
in Designing Applications with JBuilder.

Using the object gallery


The object gallery gives you access to wizards you can use to create basic
implementations 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
that you configure and select your application server for your project
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 6-3


6-4 Introducing JBuilder
Chapter

JBuilder projects
Chapter7
7
Every time you do any work within JBuilder’s IDE, you do it within a
project. A JBuilder project is an organizational structure that holds all the
files you need to perform the unit of work you define, including the
directories those files are in and all the paths, settings, and resources they
need. You decide what goes into your project.
A project is logical, not physical. In other words, the files your project
requires can be in any folder. If you reorganize the structure of your
project, it won’t have any effect on the directories that exist on your
system.

Creating a new project


To create a new project,
1 Choose File|New Project or choose File|New to display the object
gallery, click the Project tab, and double click the Project icon.

JBuilder projects 7-1


Creating a new project

The Project wizard appears:

2 Type in the name you want to give your project in the Name field, such
as MyProject, for example.
You could accept the default name JBuilder suggests, but you’ll usually
want to have a more meaningful name. JBuilder adds a .jpx extension
to your project name when it creates the project file, which contains a
list of all files in your project and holds all project settings. The project
file is an XML file.
As you specify a project name, you’ll see the name you select appended
to the current directory specified in the Directory field, which becomes
the project directory. The project directory determines where the
directory that contains the project file is located. You can change the
project directory location if you wish, but for your first projects, the
default directory is probably sufficient.
If you are curious about other options on the first page of the Project
wizard, click the Help button.

7-2 Introducing JBuilder


Creating a new project

3 Click the Next button to go to the next page of the Project wizard:

The page of the Project wizard is all about paths. For many projects,
you need not make any changes to these paths. But you can always do
so when you want to.
The JDK field indicates the JDK version you are using for this project.
JBuilder gives you the option of switching JDK versions if you click the
JDK ... button.
The Output Path specifies where the files JBuilder generates when you
compile are stored.
The Backup Path specifies where backup version of the files are stored.
The Working Directory is the directory from which JBuilder starts your
project when it is launched.
The Default path on the Source page specifies the source directory
where all your source files for this project are stored.
To read more about these fields and others on this page of the wizard,
click the Help button. For many simple projects, you won’t need to
make any changes.
4 Click Finish. (You could click the Next button instead to go on to the
third page of the Project wizard, but that page offers more advanced
features you are unlikely to need for your first projects. To read about
using the third page, go to the third page and click the Help button in
the Project wizard.)
When you choose Finish, JBuilder creates your new project. You’ll see
the project file appear in the project pane:
For more information about creating projects, see “Creating and
managing projects” in Building Applications with JBuilder. To quickly

JBuilder projects 7-3


Adding files to a project

create projects from existing code, see “Creating a project from existing
files” in Building Applications with JBuilder.

Adding files to a project


If you have JBuilder SE or JBuilder Enterprise, JBuilder will use its
automatic source path discovery feature and automatically add the folders
and files that are in your project’s source directory, if any exist. (You can
turn this feature off, if you wish; see “Automatic source packages” in
Building Applications with JBuilder for more information.)
If you are using JBuilder Personal or the automatic source path discovery
feature is off, add files and packages to a new project by following these steps:
1 Click the Add Files/Packages button on the project pane toolbar or
right-click the project file node in the project pane and choose Add
Files/Packages from the context menu.
The Add Files Or Packages To Project dialog box appears.
2 Select either the Explorer page to add a file or the Packages page to add
a package.
3 Navigate to the file or package you want to import and select it. You
can Shift+click or Ctrl+click to select multiple file names.
4 Click OK.
The new package or file appears as a node in the project pane.

Viewing a file
To view a file in a project, so you can examine it and edit it, double-click a
file node in the project pane. If a file is in a package, open the package
node first by either double-clicking the package icon or by clicking the
symbol to the left of the package icon top. Once you can see all the files in
the package, double-click the one you want to view.
Each open file of a project appears in the content pane of the AppBrowser.
A tab with file name appears for each open file in your project. You can
quickly close any of these files, but clicking the X icon on the left side of
the file name tab. You can also right-click the tab to discover other options
for closing and managing the file in the project.
See “Switching between files” in Building Applications with JBuilder for a
quick way to switch quickly between open files in the content pane when
you have many files open.

7-4 Introducing JBuilder


Adding a new Java source file

Adding a new Java source file


JBuilder gives you several ways to create new Java files. When you use
JBuilder’s wizards, they often create and add one or more Java files to
your project. For example, the Class wizard creates a Java class and the
Application wizard creates two Java files that together make up a Java
application. The following information describes how to create and add a
Java class to a project and how to create an empty file to which you can
add any code you like.
To create a Java class using the Class wizard,
1 Choose File|New, click the General tab, and double-click the Class icon
to start the Class wizard.

2 Click the Help button to read more about using the Class wizard.
3 Fill in the fields of the Class wizard appropriately.
4 Click OK when you are finished.
The wizard creates a the class file you specified and places it in your
project. It appears as a node in the project pane.
To create an empty file to your project to which you can add your Java
code,
1 Choose File|New File to open the Create New File dialog box or choose
File Open File to open the Open File dialog box.
2 Type in the name of the file.
3 Choose the .java file type from the drop-down list or include the .java
extension when you type in the name.

JBuilder projects 7-5


Removing and deleting

4 Click OK.
The new empty file appears in the content pane, but you won’t see it in
the project pane.
5 Add the code you want to the new file.
6 Choose File|Save “<file name>” or press Ctrl+S to save the file.
7 Click the Add Files/Packages button on the project pane toolbar or
right-click the project file node in the project pane and choose Add
Files/Packages from the context menu.
The Add Files Or Packages To Project dialog box appears.
8 Select the Explorer page to add a file.
9 Navigate to the file you just created select it and click OK.

Removing and deleting


You can both remove and delete files and folders from your project.
Removing files and folders removes them from your project but not from
your system’s drive. Deleting files and folders removes them from your
project and also erases them permanently from your system’s drive.
To remove files, folders, and packages from your project (but not from
your system),
1 Select the node(s) you want removed in the project pane and click the
Remove From Project button on the toolbar of the project pane or
right-click the node and choose Remove From Project from the context
menu.
2 When the Remove From Project dialog box appears asking you if you
are sure you want to remove the selected node(s), click OK.
The selected node(s) disappear from the project pane and from your
project. If you selected a folder node, any files in the folder are removed
also.
To delete files, folders, and packages from your project and from your
system’s drive, right-click the node you want to delete and choose Delete
“<node name>” on the context menu.

Renaming projects and files


To rename a project or file,
1 Select the project or file in the project pane.

7-6 Introducing JBuilder


Opening an existing project

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 and click OK.
You can also rename an open file using the file’s tab at the top of the
content pane:
1 Right-click the file tab at the top of the content pane.
2 Select Rename “<node name>”.
3 Enter the new name in the Rename dialog box and click OK.
Note Renaming a file does not change the file type. To change the file extension,
use File|Save As.
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.

Opening an existing project


To open an existing project,
1 Choose File|Open Project.
2 Navigate to the project directory where the project you want to open
exists. (Click the Help button for detailed help on using the Open
Project or Project Group dialog box.)
3 When the project directory is selected, double-click the project file for
the project you want to open in the pane on the right side of the dialog
box or click the project file and choose OK.

Learning more about projects in JBuilder


While this chapter presents enough information to get you started using
JBuilder projects, you’ll also want to read “Creating and managing
projects” and “Managing paths” in Building Applications with JBuilder.
The first chapter provides more detailed information about project
management and explores more advanced topics and features. The second
chapter explains how JBuilder uses paths to manage projects and
discusses working with libraries. You should have a good understanding
of these chapters to fully understand all that JBuilder does for you and
how it does it.

JBuilder projects 7-7


7-8 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 pane 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 shows the differences (diff blocks) between the two files.
You can undo individual diff blocks in the new file, reverting the block of
code to match the old file. 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 code in the
same part of the file, JBuilder can make them the same by replacing the
newer file’s block of code with the corresponding block of code 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 four 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.
• The Merge Conflicts page, available in JBuilder Enterprise, displays any
merge conflicts reported by the version control system.
All but the Merge Conflicts page 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
The version of the file that’s in the buffer. The buffer version includes
unsaved changes.
The latest saved version of the file.

A backup version of the file.

The version of the file that you checked out from the repository. This is a
feature of JBuilder Enterprise.
A file version from a version control system. This is a feature of JBuilder
Enterprise.

8-4 Introducing JBuilder


Using the history view

Tip With your cursor in a revision list, scroll through the list by pressing Enter
or by using your keyboard arrow keys.
The Contents and Diff pages have a source viewer. The source viewer
displays the source code of the file version selected in the revision list. You
can copy and paste from the source viewer into the editor, though you
cannot edit the source viewer directly. This simplifies retrieving old work
while it protects the integrity of the prior file versions.

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 Revert To Previous Revision button makes the version you have
selected the most current version again. The old version becomes the most
recent. This button is available from the Contents and Info pages. The Info
page is a feature of JBuilder Enterprise.
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
Synchronize Scrolling synchronizes scrolling between the source viewers
in the Contents or Diff History pages and the editor. It matches the line of
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. The Diff page is a feature of JBuilder SE and Enterprise.
Synchronize Scrolling is also a checkbox option in the File|Compare Files
dialog box.

Smart Diff
When Smart Diff is enabled, code formatting and changes to the white
space are ignored when you use JBuilder to compare two versions of a file.
This button is available in the Diff page. The Diff page is a feature of
JBuilder SE and Enterprise.

Comparing files and versions 8-5


Using the history view

Contents page
The Contents page of the history view displays all available versions of
the active file. The revision list at the top allows you to sort the file
versions by version type, revision number, label, date of change, or
author. Click on a heading to sort by that heading. Click again to reverse
the sort order. Select a version in the revision list to view its source in the
source viewer:

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. If there are many diff
blocks resulting from changes in code format, use Smart Diff to filter out
format-related changes, such as the location and number of blank lines,
the amount of indentation, or the use of spaces.
Tip When your cursor is in the source view pane of the Diff page, you can
press Shift+F10 to open a context menu with options to enable or disable
Smart Diff, and navigate to previous and next diff blocks.
Note 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.

Comparing files and versions 8-7


Using the history view

Info page
This is a feature of The Info page of the history view displays the full text of labels and
JBuilder Enterprise comments for any selected version of the active file. The revision list at the
top allows you to sort the file versions by version type, revision number,
label, date of change, author, or comment. The Refresh Revision Info and
Revert To Previous Revision buttons are enabled on this page.
To use the Info page, select a version from the revision list. Its label (if it
has one) and the comments that were entered describing the revision are
displayed in the lower part of the page:

The Info page is a screening tool. It allows you to sift through the
comments of all of the revisions of a file so you can get an overview of the
changes made to that file.
For further information on any of these features, press F1 from within any
of the History pages. This displays context help for the content pane.
Select History from the table in the context help.

8-8 Introducing JBuilder


Using the history view

Merge Conflicts page


This is a feature of The Merge Conflicts page automates the resolution of merge conflicts that
JBuilder SE and can occur while you are working with JBuilder’s integration of Concurrent
Enterprise Versioning System (CVS) or Visual SourceSafe (VSS). The Merge Conflicts
page is only enabled when conflicts are encountered.
When a merge conflict occurs, the Merge Conflicts page displays the
workspace source side-by-side with the repository source, with the
conflicting blocks of code or text highlighted. Radio buttons next to the
highlighted blocks of conflicting code allow you to easily select which
block of code you want to keep. The preview pane at the bottom of the
Merge Conflicts page shows what your workspace file will look like when
you apply the changes.

Comparing files and versions 8-9


Using the history view

Lines for a conflict that has been selected to be kept are highlighted in
yellow, and are further indicated by plus (+) signs in the gutter. Changes
to be discarded are highlighted in red and have minus (-) signs in the
gutter. If there are multiple conflicts, you can click the navigation arrows
at the bottom left corner of the page to scroll forward and back between
pairs of conflicts. The preview pane at the bottom of the Merge conflicts
page shows what the file source will look like when the changes are
applied. By default, the changes in the workspace are selected to be
retained.
When you have selected the changes you want to keep, click Apply to
apply the changes in the editor buffer. This updates the file you are
working on. Applying the changes does not save the file or check in
(commit) the changes to the repository. Until you commit your changes,
you can use the undo command (Edit|Undo or Ctrl+z) to restore the
conflicts. The undo command is not available from the history pane, so
you will need to switch to a different view.
The Merge Conflicts page is enabled only when merge conflicts occur
when you are using JBuilder’s integration of Concurrent Versioning
System (CVS) or Visual SourceSafe (VSS). For more information on
resolving merge conflicts with CVS or VSS, see “Working on an existing
project in CVS” or “Working on an existing project in VSS” in Team
Development Using JBuilder.

8-10 Introducing JBuilder


Chapter

Tutorial: Building an applet


Chapter9
9
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.
The completed tutorial is provided as a sample for your convenience. To
view the source files or run the application, open FirstApplet.jpx in the
<jbuilder>/samples/Tutorials/FirstApplet directory. For users with
read-only access to JBuilder samples, copy the samples directory into a
directory with read/write permissions.
Important Before beginning this tutorial, read the overview which discusses
important applet issues.
See the Tutorials section in the JBuilder Quick Tips for useful information
about viewing and printing tutorials. The Accessibility options section in

Tutorial: Building an applet 9-1


Overview

the JBuilder Quick Tips contains tips on using JBuilder features to


improve JBuilder’s ease of use for people with disabilities.
For information on documentation conventions used in this tutorial and
other JBuilder documentation, see “Documentation conventions” on
page 2-4.

Overview
It’s important to remember when designing applets that browser support
for Java is limited. As of this writing, Microsoft Internet Explorer and
Netscape Navigator 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://www.javasoft.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 Web Application Developer’s Guide.

9-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 in-depth information on applets and deployment, see “Working with


applets” in Web Application Developer’s Guide and “Deploying Java
programs” in Building Applications with JBuilder.

Step 1: Creating the project


Before beginning this tutorial, read the “Overview” on page 9-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 9-3


Step 1: Creating the project

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


managing projects” in Building Applications with JBuilder.
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.

9-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” in Building
Applications with JBuilder.
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” in Building Applications with JBuilder for
information on switching or editing the JDK
• “Running applets” in Web Application Developer’s Guide for
information on running applets in JBuilder
• “How JBuilder constructs paths” in Building Applications with
JBuilder.
• “Where are my files?” in Building Applications with JBuilder.
6 Click Next to go to Step 3 of the wizard.
7 Make the following changes in the appropriate fields of Step 3:
a Accept the Encoding and Automatic Source Packages defaults. The
Automatic Source Packages option is a feature of JBuilder SE and
Enterprise.
b Type Good Evening in the Title field of the class Javadoc fields.
c Enter your name, company name, and a description of your applet in
the appropriate optional fields.

Tutorial: Building an applet 9-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.

9-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 9-2 for more
information.
6 Check Generate Standard Methods.
Step 1 of the Applet wizard should look like this:

Tutorial: Building an applet 9-7


Step 2: Generating your source files

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
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://www.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:

9-8 Introducing JBuilder


Step 2: Generating your source files

The <applet> tag in the HTML file can include these attributes:

codebase This optional attribute specifies the path relative to


the applet HTML file that the browser searches to find
any necessary class files. A value of “.” specifies the
same directory as the HTML file running the applet.
The codebase attribute is required when the class files
are in a different directory than the HTML file.
code This required attribute, which is automatically
inserted by JBuilder’s Applet wizard, is the fully
qualified class name (package name + class name) of
the applet class that contains the init() method.
You’ll see it in the HTML file when it is generated. In
this example, the fully qualified class name is
firstapplet.GoodEveningApplet.class.
archive This optional attribute, which is not included in the
code generated by the Applet wizard, is required
when the applet is deployed in a JAR, ZIP, or CAB
file. Archive files must be in the directory specified by
codebase.
name This optional attribute names the applet.
width/height These required attributes determine the width and
height of the applet display area in pixels.
hspace/vspace These optional attributes determine the horizontal
padding (left and right margins) and vertical padding
(top and bottom margins) around the applet in pixels.
align This optional attribute determines the alignment of
the applet on the HTML page.

Important The values for codebase, code, archive, and name must be in quotation
marks and are case-sensitive.

See also
• “<applet> tag attributes" topic in 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 9-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.*;

9-10 Introducing JBuilder


Step 3: Compiling and running your 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.
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 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 command-line
tool.
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 9-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 Click Exit in the “Good Evening” applet to close it.
3 Right-click the GoodEveningApplet tab in the message pane and
choose Remove “GoodEveningApplet” Tab to close any runtime
messages.

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


Step 4: Customizing your applet’s user interface

c Choose 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.

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.

9-14 Introducing JBuilder


Step 4: Customizing your applet’s user interface

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

Tutorial: Building an applet 9-15


Step 4: Customizing your applet’s user interface

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 choose
Orange from the list.
7 Change the background color of lower to Magenta.
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-16 Introducing JBuilder


Step 5: Adding AWT components to your applet

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 choose Run using
“GoodEveningApplet.”
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 choosing Remove “GoodEveningApplet” Tab.

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.

Tutorial: Building an applet 9-17


Step 5: Adding AWT components to your applet

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

9-18 Introducing JBuilder


Step 5: Adding AWT components to your applet

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: G’day, 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.
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 “G’day, 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.

Tutorial: Building an applet 9-19


Step 6: Editing your source code

10 Click the AWT Button component and drop it to the left of the “G’day,
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.

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.

9-20 Introducing JBuilder


Step 6: Editing your source code

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

Tutorial: Building an applet 9-21


Step 6: Editing your source code

c Select the Events tab in the Inspector.


d Double-click to the right of the itemStateChanged event.
JBuilder generates the method code and takes you to the source code
with the cursor inserted in the method.
void choice1_itemStateChanged(ItemEvent e) {

}
e Add the following code indicated in bold to connect the correct
language panel to the language choice:
void choice1_itemStateChanged(ItemEvent e) {
if ("English".equals(choice1.getSelectedItem())){
cardLayout1.show(lower, "panel1");
}
else if ("German".equals(choice1.getSelectedItem())){
cardLayout1.show(lower, "panel2");
}
else if ("Pig Latin".equals(choice1.getSelectedItem())){
cardLayout1.show(lower, "panel3");
}
else if ("Swedish".equals(choice1.getSelectedItem())){
cardLayout1.show(lower, "panel4");
}
else if ("Australian".equals(choice1.getSelectedItem())){
cardLayout1.show(lower, "panel5");
}
}
Tip You can use code templates to generate code. Type if and press Ctrl+J
to access the code templates pop-up window. Use the arrow keys to
navigate the selections. Select the if-else if template and press Enter.
The code is generated:
if () {

}
else if{

}
3 Choose File|Save All.
4 Run the applet by right-clicking GoodEveningApplet.html in the project
pane and selecting Run using “GoodEveningApplet.”

9-22 Introducing JBuilder


Step 6: Editing your source code

The “Good Evening” applet runs in Sun’s appletviewer:

If there are any errors, they appear in the message pane at the bottom of
the AppBrowser. Select an error message and press F1 for Help. Select
the error message to highlight the code in the editor. Sometimes the
error may be before or after the highlighted line of code. Fix the errors,
save the project, and run the applet again.
5 Test the drop-down list. The language selected from the list should
match the language on the panel below it.
6 Exit the applet.
Now, add a button label and a button event for button1 on panel5. When
you push the button, the “G’day, 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
“G’day, Mate” to red.

Tutorial: Building an applet 9-23


Step 7: Deploying your applet

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.
“G’day, Mate” should turn red.
Your applet should look similar to this:

4 Exit the 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.

9-24 Introducing JBuilder


Step 7: Deploying your applet

• 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 “Deploying the Text Editor application”
in Designing Applications with JBuilder
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

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.

Tutorial: Building an applet 9-25


Step 7: Deploying your applet

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

9-26 Introducing JBuilder


Step 7: Deploying your applet

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 9-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.
4 Choose Wizards|Archive Builder to open the Archive Builder.

Tutorial: Building an applet 9-27


Step 7: Deploying your applet

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 Among the Classes options, select the Specified Only option.
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.

9-28 Introducing JBuilder


Step 7: Deploying your applet

11 Click the Add Classes button and select the firstapplet package. Click
OK to close the dialog box.
The package displays in the Specified Classes 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.
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.

Tutorial: Building an applet 9-29


Step 8: Modifying the HTML file

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
• “Deploying with 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>
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.

9-30 Introducing JBuilder


Step 8: Modifying the HTML file

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 9-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 NT, 2000, and XP: 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 at the end of the tutorial and see these topics for common errors:
• “Solving common applet problems” at
http://www.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.

9-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 9-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://www.formlessvoid.com/jc/index
• 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 9-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>

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

Tutorial: Building an applet 9-35


Applet source code

try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
this.setLayout(borderLayout1);
upper.setBackground(Color.orange);
lower.setBackground(Color.magenta);
lower.setLayout(cardLayout1);
panel1.setLayout(borderLayout2);
panel2.setLayout(borderLayout3);
panel3.setLayout(borderLayout4);
panel4.setLayout(borderLayout5);
panel5.setLayout(flowLayout1);
panel1.setBackground(new Color(190, 173, 255));
panel2.setBackground(new Color(83, 182, 255));
panel3.setBackground(new Color(255, 149, 66));
panel4.setBackground(new Color(239, 107, 140));
panel5.setBackground(new Color(17, 198, 99));
label1.setFont(new java.awt.Font("Serif", 1, 20));
label1.setForeground(Color.blue);
label1.setText("Select a language");
label2.setFont(new java.awt.Font("Dialog", 1, 24));
label2.setForeground(Color.black);
label2.setText("Good Evening");
label3.setFont(new java.awt.Font("Dialog", 1, 24));
label3.setForeground(Color.black);
label3.setText("Guten Abend");
label4.setFont(new java.awt.Font("Dialog", 1, 24));
label4.setForeground(Color.black);
label4.setText("Oodgay vening eay");
label5.setFont(new java.awt.Font("Dialog", 1, 24));
label5.setForeground(Color.black);
label5.setText("God Kvall");
choice1.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(ItemEvent e) {
choice1_itemStateChanged(e);
}
});
label6.setFont(new java.awt.Font("Dialog", 1, 24));
label6.setForeground(Color.black);
label6.setText("G'day, 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");

9-36 Introducing JBuilder


Applet source code

panel1.add(label2, BorderLayout.NORTH);
lower.add(panel2, "panel2");
panel2.add(label3, BorderLayout.SOUTH);
lower.add(panel3, "panel3");
panel3.add(label4, BorderLayout.EAST);
lower.add(panel4, "panel4");
panel4.add(label5, BorderLayout.WEST);
lower.add(panel5, "panel5");
panel5.add(button1, null);
panel5.add(label6, null);
this.add(upper, BorderLayout.NORTH);
upper.add(label1, null);
upper.add(choice1, null);
}
/**Start the applet*/
public void start() {
}
/**Stop the applet*/
public void stop() {
}
/**Destroy the applet*/
public void destroy() {
}
/**Get Applet information*/
public String getAppletInfo() {
return "Applet Information";
}
/**Get parameter info*/
public String[][] getParameterInfo() {
return null;
}

void choice1_itemStateChanged(ItemEvent e) {
if ("English".equals(choice1.getSelectedItem())){
cardLayout1.show(lower, "panel1");
}
else if ("German".equals(choice1.getSelectedItem())){
cardLayout1.show(lower, "panel2");
}
else if ("Pig Latin".equals(choice1.getSelectedItem())){
cardLayout1.show(lower, "panel3");
}
else if ("Swedish".equals(choice1.getSelectedItem())){
cardLayout1.show(lower, "panel4");
}
else if ("Australian".equals(choice1.getSelectedItem())){
cardLayout1.show(lower, "panel5");
}
}

void button1_actionPerformed(ActionEvent e) {
label6.setForeground(new Color(255,0,0));
}
}

Tutorial: Building an applet 9-37


9-38 Introducing JBuilder
Chapter

Tutorial: Using the history view


Chapter10
10
This tutorial covers the use of the history view. The history view is
available in all editions of JBuilder, though the features differ for the
different JBuilder editions. This tutorial covers all of the features available,
organized by JBuilder edition. Users of all editions of JBuilder can
complete the first two lessons. Users of JBuilder 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, so you can
focus on the history features rather than on the code you change.
Terminology describing version handling varies from tool to tool. This
tutorial uses generic terminology for the tool-independent version
handling features in JBuilder. For explanations of these terms, please see
the “Version handling glossary” on page 8-1.
The use of version control systems is discussed where appropriate. The
tutorial can be used with or without a version control system, and steps
that apply only to users of version control systems are clearly marked.
Concurrent Versions System (CVS) is a feature of JBuilder SE and
Enterprise. Microsoft Visual SourceSafe (VSS), and Rational ClearCase
integrations are a feature of JBuilder Enterprise. 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.
See the Tutorials section in the JBuilder Quick Tips for useful information
about viewing and printing tutorials. The Accessibility options section in
the JBuilder Quick Tips contains tips on using JBuilder features to
improve JBuilder’s ease of use for people with disabilities.
For information on documentation conventions used in this tutorial and
other JBuilder documentation, see “Documentation conventions” on
page 2-4.

Tutorial: Using the history view 10-1


Step 1: Generating multiple versions of a file

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. Throughout this tutorial,
we will work with files in the Welcome sample project.
To make changes to a source file,
1 Open the Welcome sample project.
The Welcome sample project, Welcome.jpx, is located in the /samples/
welcome directory of your JBuilder installation.
Note The next step is for version control users only.
2 Version control users: place the project under version control.
Note If you don’t have the necessary access to place a project into your
version control system, but you still want to see the version control
aspects of the history view, you can use the installation of CVS
provided with your JBuilder installation. CVS allows you to create a
local repository that’s completely under your control. For more
information on version control in JBuilder, see Team Development Using
JBuilder. For more information on CVS specifically, see “CVS in
JBuilder” in Team Development Using JBuilder.
3 Double-click WelcomeApp.java in the project pane if it’s not already open
and active in the content pane.
4 Look at the status bar in the content pane.

10-2 Introducing JBuilder


Step 1: Generating multiple versions of a file

The two numbers in the status bar tell you the row and column of your
present cursor position:

5 Put the cursor at the end of row 27. The text in this row reads import
javax.swing.UIManager;.
6 Press Enter at the end of row 27 to add a line below it.
7 Type import java.applet.*; in row 28.
8 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 ten 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. You can
have up to 90 backups stored in your bak directory.

Tutorial: Using the history view 10-3


Step 2: Using the Contents page

9 Change import java.applet.*; to import java.applet.Applet; and save the


file.
Note The next step is for version control users only.
10 Version control users: commit the file, and enter the comment Changed
import.java.applet.* to import.java.Applet.
This generates a version control type of version to view later.
11 Go to line 31, which reads boolean packFrame = false;, and change false
to true.
12 Save the file.
Note You are going to make one more change, but don’t save the file until you
are instructed to do so.
13 Put the cursor in row 35, column 23, which reads WelcomeFrame frame =
new WelcomeFrame;, and change the object name frame to frame2.
Your source now looks like this:
package com.borland.samples.welcome;

import java.awt.*;
import javax.swing.UIManager;
import java.applet.Applet;

public class WelcomeApp {


boolean packFrame = true;

// Construct the application


public WelcomeApp() {
WelcomeFrame frame2 = new WelcomeFrame();

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.

10-4 Introducing JBuilder


Step 2: Using the Contents page

1 Choose the History file view tab. The Contents page appears:

Note The Revision Content section in your Contents page may vary from the
page shown here, depending on whether or not you are using version
control.
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.

Tutorial: Using the history view 10-5


Step 2: Using the Contents page

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

10-6 Introducing JBuilder


Step 2: Using the Contents page

8 Select the entire statement and copy it:

Choose 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 Contents page. 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.
Choose 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 10-7


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
In this step of the tutorial, you will learn how to:
• Sort revisions in the Differences section
• Undo changes in a selected revision
• Use Smart Diff to filter unimportant changes when comparing file
versions

Sorting revisions
To sort revision information,
1 Select the Diff tab in the history pane.
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.

Undoing changes
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.

10-8 Introducing JBuilder


Step 3: Using the Diff page

JBuilder retrieves the differences and displays them in the source


viewer:

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.

Tutorial: Using the history view 10-9


Step 3: Using the Diff page

3 Click the diff arrows on the left of the status bar at the bottom of the
Diff page to move from one block of code with differences to another.
As a alternative to using the diff arrows, you can press Shift+F10 to open
a context menu (your cursor must be in the source view pane) and
choose Previous Diff Block or Next Diff Block from the context menu to
navigate between diff blocks.
4 Click the Undo Change button.
An option called Undo Above Changes appears.
5 Click the option. Line 28 now reads import java.applet.*;.
import java.applet.Applet; disappears and the diff block is resolved.

Using Smart Diff


The Smart Diff feature excludes code formatting and changes to the white
space from consideration when comparing two versions of a file. To see
how the Smart Diff feature works,
1 Click the Source file view tab.
2 Open the Project Properties dialog box (Project|Project Properties), and
select the Formatting tab.
3 Click Import to open the Import Code Formatting Settings dialog box.
4 Select the Expanded.codestyle code formatting settings file and click OK.
The expanded code format specified by the Expanded.codestyle code
formatting settings file significantly increases the amount of white
space in files.
5 Click OK to close the Project Properties dialog box.
6 Choose Edit|Format All to apply the formatting changes to
WelcomeApp.java.
Note how the code formatting changes in the file.
7 Return to the history pane, and select the Diff tab.
Note the increase of diff blocks resulting from the formatting change.
The added diff blocks are simply due to added spaces and lines.

10-10 Introducing JBuilder


Step 4: Using the Info page

8 Click the down arrow next to the Smart Diff button located in the
bottom right corner of the Diff page, and choose the Use Smart Diff
option displayed.

The Smart Diff button changes to indicate that Smart Diff is enabled.
When you enable Smart Diff, all but the original diff block disappear.
The Smart Diff feature can be especially useful when multiple
developers are sharing files, and files are either formatted to suit the
personal preferences of individual developers or files are formatted for
overall consistency.
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.”

See also
• “Formatting your code” on page 5-8 for more information about
specifying and applying code formatting preferences

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 Select 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 10-11


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 reverted file 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.
For more information on the history view and the History pages, see
Chapter 8, “Comparing files and versions.”

See also
• CVS in JBuilder tutorial in Team Development Using JBuilder for an
example of how to use the Merge Conflicts page

10-12 Introducing JBuilder


Index
A C
AppBrowser 4-1 class reference documentation 2-12
collapsing trees 4-16 classes
content pane 4-12 finding 4-18
debugger 4-15 ClassInsight 5-14
editor 5-1 code
expanding trees 4-16 applying formatting 5-9
hiding panes 4-13 autocompletion 5-13
menu bar 4-3 automating 6-1
message pane 4-13 CodeInsight 5-12
moving between panes completing automatically 5-14
navigating creating in editor 5-1
AppBrowser trees 4-16 drilling into 4-10
opening multiple AppBrowsers 4-2 formatting 5-8
project pane 4-5 shortcuts 5-12
resizing content pane 4-13 code symbols
searching in 4-16 finding definition of 5-7
status bars 4-16 finding references to 5-8
structure pane 4-8 code templates
toolbar 4-3 creating 5-17
applets CodeInsight 5-12
tutorial 9-1 configuring 5-16
applications failure 5-13
tutorial 3-1 keyboard shortcuts 5-13
applying filters to packages 4-6 comments
Javadoc documentation 5-10
B revision information 8-8
comparing files
bookmarks diff view 8-2
Help Viewer 2-9 excluding formatting changes 8-5
books source view 8-2
JBuilder 2-1 synchronizing scrolling 8-2
Borland component palette 6-1
contacting 2-13 configuring
developer support 2-13 CodeInsight 5-16
e-mail 2-15 content pane 4-12
newsgroups 2-14 file tabs 4-12
online resources 2-14 file view tabs 4-13
reporting bugs 2-15 hiding other panes 4-13
technical support 2-13 history view 8-4
World Wide Web 2-14 resizing 4-13
braces Contents page 8-6
wrapping around code block 5-9 copying from the Help Viewer 2-9
browsing classes 4-18 copying text
See also Find Classes from the message pane 4-14
browsing symbol definitions 5-7 curly braces
wrapping around code block 5-9
customizing IDE 4-19

Index I-1
D F
date Favorites 4-19
revised 8-8 files
Debug page (Project Properties dialog box) 4-15 comparing any two 8-1, 8-2
debugger 4-15 viewing structure 4-8
debugging 5-16 Find Classes 4-18
decreasing code text size 5-6 Find Definition 5-16
designers Find Definition command 5-7
column designer 6-1 Find References command 5-8
menu designer 6-1 finding classes 4-18
UI designer 6-1 finding references to
diff code symbol 5-8
defined 8-1 finding text 5-6
diff blocks finding text in Help 2-8
defined 8-1 current topic 2-9
undo changes 8-6 full-text search 2-8
viewing 8-6 font
Diff page 8-6 resizing in editor 5-6
diffs font resizing in IDE 5-6
comparing any two files 8-2 font size
documentation changing in editor 4-16
JBuilder 2-1 fonts
documentation conventions 2-4 JBuilder documentation conventions 2-4
platform conventions 2-5 formatting
drilling down applying curly braces to code blocks 5-9
in file structure 4-8, 4-10 applying to code 5-9
code 5-8
E free-floating message pane 4-15
editor G
code templates 5-17
displaying line numbers 5-4 glossary
Find Definition command 5-7 version handling terms 8-1
Find References command 5-8 Go To Line 5-4
Javadoc tips 5-10 gutter
keymaps 5-1 using to select text 5-5
printing source code 5-11 gutter margin
searching 5-6 line numbers 5-4
selecting text 5-5
splitting view 5-3 H
todo tags 5-11
editor emulations 5-1 help
editor, using 5-1 using online 2-6
enlarging code text 5-6 Help Viewer
error messages bookmarking 2-9
viewing and finding 4-11 copying text from 2-9
ExpressionInsight 5-16 finding text in current topic 2-9
expressions full-text search 2-8
auto-evaluating 5-16 navigating in 2-11

I-2 Introducing JBuilder


table of contents 2-7
user interface 2-7
L
using 2-7 label, revision 8-8
using index of 2-8 library reference documentation 2-12
using keyboard keys in 2-11 line number
zooming the view 2-9 using to select text 5-5
hiding message pane 4-15 line numbers
hierarchical views 4-8 displaying in editor 5-4
history view go to specific line 5-4
Contents page 8-6 locating text 5-6
Diff page 8-6
icons 8-4 M
Info page 8-8
Merge Conflicts page 8-9 magnifying glass tool 4-16
overview 8-4 manuals
tutorial 10-1 Builder 2-1
MemberInsight 5-14
menu bar 4-3
I menus
icons commands 4-3
history view 8-4 toolbar shortcuts 4-3
revision list 8-4 merge conflicts
version control types 8-4 resolving 8-9
IDE Merge Conflicts page 8-9
customizing 4-19 message pane 4-13
IDE options 4-19 copying text from 4-14
IDE Options dialog box 4-19 docking 4-15
identifiers hiding 4-15
Find Definition command 5-7 showing 4-15
illegal syntax notification 5-12 undocking 4-15
import options
ClassInsight 5-14 N
increasing code text size 5-6
Info page 8-8 navigating
inserting classes AppBrowser panes 4-16
ClassInsight 5-14 Help Viewer 2-11
shortcut commands 4-16
newsgroups
J Borland 2-14
Javadoc public 2-15
ToDo folder 4-9
todo tags 5-11 O
Javadoc documentation
comments 5-10 object gallery 6-3
shortcuts commands 5-10 wizards 6-3
JBuilder
AppBrowser 4-1 P
parameter lists 5-16
K ParameterInsight 5-16
keybinding mode 4-16 previous file versions
keymapping 4-16 reverting to 8-5
keymaps 5-1 printing
customizing 5-2 from the editor 5-11
source code 5-11

Index I-3
project files selecting
viewing structure 4-8 text from line number gutter 5-5
project pane shortcut commands
context menu 4-6 coding 5-12
filtering packages 4-6 shortcut commands for Javadoc 5-10
project toolbar 4-5 showing message pane 4-15
searching 4-5 Smart Diff
projects enabling 8-5
adding classes 4-6 Smart Diff button (history pane) 8-5
adding files 4-6 sorting
creating 4-6 revision list 8-6
source pane
Q splitting view 5-3
source viewers
quick links synchronizing scrolling 8-5
Favorites 4-19 splitter bar
AppBrowser 4-13
R status bars
AppBrowser 4-16
reference documentation 2-12
structure pane 4-8
layout 2-12
error messages 4-11
Refresh Revision Info button (history pane) 8-5
navigating file structure 4-8
repository
sorting order 4-8
defined 8-1
ToDo folder 4-9
resizing code text 5-6
using to navigate source code 4-10
resizing content pane 4-13
Synchronize Scrolling button (history pane) 8-5
Revert To Previous Revision button (history
synchronizing scrolling
pane) 8-5
in source viewers 8-5
revision date 8-8
syntax errors
revision information
viewing and finding 4-11
viewing 8-8
revision label 8-8
revision list T
icons 8-4 tabs
refreshing 8-5 content pane 4-12, 4-13
sorting 8-6 templates
revision management 8-4 code 5-17
See also history view text
selecting in editor 5-5
S text searches 5-6
ToDo folder 4-9
search commands 5-6
todo tags 5-11
Search menu 5-6
tool tips 5-16
searching 4-17
toolbar (main window) 4-3
in AppBrowser 4-16
tools
in project pane 4-5
visual design 6-1
in the editor 5-8
trees
in trees 4-17
navigating 4-16
using Find Definition 5-7
searching 4-17
with Find References 5-8
tutorials
with incremental typing 4-17
creating an applet 9-1
searching classes 4-18
creating an application 3-1
See also Find Classes
using the history view 10-1

I-4 Introducing JBuilder


U W
UI designer 6-1 Watch page 4-15
undocking message pane 4-15 wizards
Usenet newsgroups 2-15 object gallery 6-3
workspace
V defined 8-1
version control
comparing files 8-1
history view 8-4
merge conflicts 8-9
version control types
icons 8-4
version handling
reverting to prior file versions 8-5
viewing previous versions 8-4
visual design tools 6-1

Index I-5

S-ar putea să vă placă și