Documente Academic
Documente Profesional
Documente Cultură
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
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.
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.
Documentation conventions
The Borland documentation for JBuilder uses the typefaces and symbols
described in the following table to indicate special text.
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.
Online resources
You can get information from any of these online sources:
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/.
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.
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.
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.
11 Choose File|Save All to save the source files and the project file.
Note The source files are saved to:
/<home>/jbproject/HelloWorld/src/helloworld.
The class files generated from the source files by the Java compiler are
saved to: /<home>/jbproject/HelloWorld/classes/helloworld.
Note The running application in this tutorial reflects the Windows Look &
Feel.
2 Choose File|Exit in the “Hello World” application to close it.
3 Click the Close button on the the HelloWorldClass tab in the message
pane close any messages.
3 Click the Swing Containers tab on the component palette above the UI
designer and choose the JPanel component to add a panel to your
design.
Tip Place the cursor over a component on the palette to see its name in a
tool tip.
4 Click the center of the frame in the UI designer to drop the component
into the center of your design’s frame.
Note The constraints property in the Inspector should be Center. If not, click
the column to the right of the constraints property, and choose Center
from the drop-down list.
jPanel1 is now selected in your application design and in the
component tree.
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 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.
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.
}
You can now enter code that defines the event.
7 Type the following code indicated in bold:
void jButton4_actionPerformed(ActionEvent e) {
jLabel1.setForeground(new Color(255,0,0));
}
Tip Use CodeInsight to complete the code for you. Type jLabel1. and wait
for the pop-up window or press Ctrl+spacebar to invoke it. If CodeInsight
fails to appear, check the settings on the CodeInsight page of Editor
Options (Tools|Editor Options). Type setfor to highlight
setForeground(Color) in the pop-up window or use the arrow keys. Press
Enter.
Now, when you run the application and push the “Push Me” button,
“Hello World!” should turn red.
8 Choose File|Save All.
9 Choose Project|Make Project “HelloWorld.jpx”.
10 Choose Run|Run Project.
11 Click the “Push Me” button. The color of the “Hello World!” text turns
red.
5 Accept the defaults in Steps 3 through 6 and click Next in each step.
6 Click Finish in Step 7 to close the Archive Builder.
An archive node called Application appears in the project pane. You can
modify this file by right-clicking and selecting Properties.
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.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
/**
* Title: HelloWorld
* Description: This is the "Hello World" tutorial.
* Copyright: Copyright (c) 2001
* Company: MyCompany
* @author MyName
* @version 1.0
*/
/**Component initialization*/
private void jbInit() throws Exception {
image1 = new ImageIcon
(helloworld.HelloWorldFrame.class.getResource("openFile.gif"));
image2 = new ImageIcon
(helloworld.HelloWorldFrame.class.getResource("closeFile.gif"));
image3 = new ImageIcon
(helloworld.HelloWorldFrame.class.getResource("help.gif"));
//setIconImage(Toolkit.getDefaultToolkit().createImage
(HelloWorldFrame.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
border1 = BorderFactory.createLineBorder(Color.gray,2);
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Hello World");
statusBar.setText(" ");
jMenuFile.setText("File");
jMenuFileExit.setText("Exit");
jMenuFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuFileExit_actionPerformed(e);
}
});
jMenuHelp.setText("Help");
jMenuHelpAbout.setText("About");
jMenuHelpAbout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuHelpAbout_actionPerformed(e);
}
});
jButton1.setIcon(image1);
jButton1.setToolTipText("Open File");
jButton2.setIcon(image2);
jButton2.setToolTipText("Close File");
jButton3.setIcon(image3);
jButton3.setToolTipText("Help");
jPanel1.setBackground(Color.white);
jPanel1.setBorder(border1);
jPanel1.setLayout(gridBagLayout1);
jLabel1.setFont(new java.awt.Font("Serif", 3, 28));
jLabel1.setForeground(Color.blue);
jLabel1.setText("Hello World!");
jButton4.setText("Push Me");
jButton4.addActionListener(new java.awt.event.ActionListener() {
jMenuHelp.add(jMenuHelpAbout);
jMenuBar1.add(jMenuFile);
jMenuBar1.add(jMenuHelp);
this.setJMenuBar(jMenuBar1);
contentPane.add(jToolBar, BorderLayout.NORTH);
contentPane.add(statusBar, BorderLayout.SOUTH);
contentPane.add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jLabel1, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(45, 125,
102, 110), 10, -6));
jPanel1.add(jButton4, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(46,
148,
0, 149), 16, 0));
}
/**File | Exit action performed*/
public void jMenuFileExit_actionPerformed(ActionEvent e) {
System.exit(0);
}
/**Help | About action performed*/
public void jMenuHelpAbout_actionPerformed(ActionEvent e) {
HelloWorldFrame_AboutBox dlg = new HelloWorldFrame_AboutBox(this);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height -
dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.show();
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
jMenuFileExit_actionPerformed(null);
}
}
void jButton4_actionPerformed(ActionEvent e) {
jLabel1.setForeground(new Color(255,0,0));
}
}
import javax.swing.UIManager;
import java.awt.*;
/**
* Title: HelloWorld
* Description: This is the "Hello World" tutorial.
* Copyright: Copyright (c) 2001
* Company: MyCompany
* @author MyName
* @version 1.0
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
/**
* Title: HelloWorld
* Description: This is the "Hello World" tutorial.
* Copyright: Copyright (c) 2001
* Company: MyCompany
* @author MyName
* @version 1.0
*/
//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();
}
}
}
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:
File|Save All Saves all open projects and files, using the current
names.
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.
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.
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.
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.
See also
• “Using @todo tags in the editor” on page 5-11
• “Conflicts in Javadoc comments” in Building Applications with JBuilder
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.
See also
• “About error and warning messages” in Building Applications with
JBuilder.
Content pane
The content pane displays all opened files in a project as a set of tabs. To
open a file in the content pane, double-click it in the project pane, or select
it and press Enter. The name of each opened file is displayed on a tab 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.
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.
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.
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.
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.
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:
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.
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.
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.
For more information about using the Keymap Editor, click its Help
button.
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.
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.
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.)
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.
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.
• 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.
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.
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:
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
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
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.
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|
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
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.
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.
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.
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
create projects from existing code, see “Creating a project from existing
files” in Building Applications with JBuilder.
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.
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.
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.
Term Definition
revision, version These terms are basically interchangeable in this context. Each
time you change a file (or revise it), you make a new version (or
revision) of that file.
diff Diff is short for difference. A diff is an area of text that is
different between two files or between two versions of the same
file.
diff block An area of difference between two files or two versions of the
same file. These are most easily seen using a diff view, where
the two files or file versions are merged into one apparent
source and differences between them are flagged.
Note that JBuilder’s diff handling mechanisms evaluate files
physically, not logically. They compare only the actual text of
the files or the versions against each other, not their logic or
code structure.
revert Make a previous version of the file the current version again.
version control A way of managing revisions that maintains records of all
changes made to every file under version control. Version
control systems generally also include other code management
features such as branching and version labeling.
Term Definition
backup copy A saved version of the file that is maintained in the local backup
directory for that file.
JBuilder uses backup copies as prior file versions. Set the
number of backups you want to keep from the Editor page of
Tools|Editor Options. When the limit is reached, the latest
versions will be kept and renumbered appropriately.
buffer The latest working version you use in JBuilder. It includes
unsaved changes.
repository In version control, where file master versions and revision
histories are kept.
workspace In version control, the local files and directory structure that
you change directly.
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.
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.
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.
Tip With your cursor in a revision list, scroll through the list by pressing Enter
or by using your keyboard arrow keys.
The Contents and Diff pages have a source viewer. The source viewer
displays the source code of the file version selected in the revision list. You
can copy and paste from the source viewer into the editor, though you
cannot edit the source viewer directly. This simplifies retrieving old work
while it protects the integrity of the prior file versions.
Synchronize Scrolling
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.
Contents page
The Contents page of the history view displays all available versions of
the active file. The revision list at the top allows you to sort the file
versions by version type, revision number, label, date of change, or
author. Click on a heading to sort by that heading. Click again to reverse
the sort order. Select a version in the revision list to view its source in the
source viewer:
Diff page
This is a feature of The Diff page displays differences between two selected versions of the
JBuilder SE and active file. The revision lists at the top allow you to sort the file versions by
Enterprise version type, revision number, or date of change. The Refresh Revision
Info and Synchronize Scrolling buttons are enabled on this page.
There are two revision lists in the Diff page. One is titled From and the
other is titled To. Select a version in the From list and select a different
In each block of difference, the diff deletion (with the minus sign) is in red
and the diff addition (with the plus sign) is in yellow. If the buffer is
selected as the To version, undo an addition by clicking the Undo button
in the gutter.
Use the diff arrows to move between diff blocks. 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.
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.
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.
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.
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.
Note The information in the class Javadoc fields appears in the project
HTML file and as optional header comments in the source code.
See also
• “Defining and using parameters” at
http://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:
The <applet> tag in the HTML file can include these attributes:
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
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.
4 Choose the AWT tab on the component palette at the top of the UI
designer.
You might need to scroll to the right on the component palette to find
the AWT tab. AWT components, unlike Swing components, are
supported by most web browsers.
Caution The UI designer always opens with the Swing components on the first
page of the component palette. If you select these Swing components
by mistake, your applet won’t run in the web browsers. Be very careful
to choose components from the AWT page of the palette.
5 Add two panels to the this panel. The top panel will contain a
drop-down list of languages to select from and a label to identify the
list. The bottom panel will contain “Good Evening” in various
languages.
a Shift+Click the AWT Panel component, java.awt.Panel, on the
component palette.
Shift+Click allows you to drop the same component multiple times
without having to select it each time from the component palette.
Now you can add multiple panels to this.
Tip Place the cursor over a component to see its name in a tool tip.
b Click twice on this in the component tree in the structure pane to
add two panels. panel1 and panel2 are added below this in the
component tree.
c Click the Selection Tool on the left side of the component palette to
disable the component selection.
d Check the constraints property for the panels in the Inspector. The
top panel in your design should be North and the bottom panel
should be Center. To check the constraints property,
1 Select a panel in the component tree or in the UI designer. If a
component is selected in the designer, small nibs show at each
corner of the component.
2 Confirm that the constraints property in the Inspector is set to
North for the top panel and Center for the bottom panel. If not,
click the column to the right of the constraints property and
choose the correct constraint from the drop-down list.
e Rename the top panel to upper:
1 Select the top panel in the component tree or the designer and
double-click the column to the right of the name property in the
Inspector.
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.
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:
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.
}
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.”
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.
• 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
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
See also
• “Using JAR Files: The Basics” at
http://java.sun.com/docs/books/tutorial/jar/basics/index.html
• “jar-The Java Archive Tool” at
http://java.sun.com/j2se/1.3/docs/tooldocs/tools.html#basic
• “Deploying Java programs” in Building Applications with JBuilder
5 Select Applet JAR from the Archive Type drop-down list in Step 1 and
click Next to continue to Step 2.
Note Select the Applet ZIP archive type if you are developing applets for
older browsers that do not support JAR files.
6 Accept the default name of Applet JAR in the name field.
7 Click the ellipsis button next to the File field and browse to the
/<home>/jbproject/applets/ directory.
8 Change the JAR file name in the File Name field to GoodEvening.jar and
click OK.
Step 2 should look like this:
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.
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
Next, add a message that tells users without Java-enabled browsers that
their browsers do not support Java; therefore, they can’t see the applet.
2 Enter the following message between the open and close <applet> tags:
You need a Java-enabled browser running JDK 1.1.x or greater to view this
applet.
The <applet> tag looks like this:
<applet
codebase = "."
code = "firstapplet.GoodEveningApplet.class"
archive = "GoodEvening.jar"
name = "TestApplet"
width = 400
height = 300
hspace = 0
vspace = 0
align = top
>
You need a Java-enabled browser running JDK 1.1.x or greater to view this
applet.
</applet>
Any web browser that does not support Java ignores the <applet> tags
and displays everything between the tags. Because a Java-enabled
browser recognizes the <applet> tags, anyone with a Java-enabled
browser will see the applet and not the message.
Important Before saving the HTML file, check the codebase and code values again.
If these values are incorrect, the applet won’t run. Remember that the
codebase value is the location of the applet code (CLASS or JAR file) in
relation to the HTML file. The value, ".", means the class file is in the
same directory as the HTML file. The code value must be the fully
qualified class name for the applet, including the package name.
3 Save and close the file.
4 Copy the modified GoodEveningApplet.html from the project’s classes
directory to the applets directory. The applets directory should contain
two files, GoodEveningApplet.html and GoodEvening.jar.
Caution Remember, JBuilder creates two HTML files: the project notes HTML
file, FirstApplet.html, located at the root of the project directory and the
applet HTML file containing the <applet> tag, GoodEveningApplet.html,
located in the project src directory. Do not copy FirstApplet.html instead
of GoodEveningApplet.html to the applets directory or your applet will not
run.
2 Test the applet in various browsers. If the applet fails to load, check that
the browser is Java-enabled. Also check the browser’s Java Console for
error messages.
To open the Java Console:
• Select Communicator|Tools|Java Console in Netscape.
• Select View|Java Console in Internet Explorer.
3 Correct any errors, redeploy your applet, and test again in the
browsers.
See also
• “Testing applets” in the Web Application Developer’s Guide
<applet
codebase = "."
code = "firstapplet.GoodEveningApplet.class"
archive = "GoodEvening.jar"
name = "TestApplet"
width = 400
height = 300
hspace = 0
vspace = 0
align = top
>
You need a Java-enabled browser running JDK 1.1.x or greater to view this
applet.
</applet>
</body>
</html>
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
this.setLayout(borderLayout1);
upper.setBackground(Color.orange);
lower.setBackground(Color.magenta);
lower.setLayout(cardLayout1);
panel1.setLayout(borderLayout2);
panel2.setLayout(borderLayout3);
panel3.setLayout(borderLayout4);
panel4.setLayout(borderLayout5);
panel5.setLayout(flowLayout1);
panel1.setBackground(new Color(190, 173, 255));
panel2.setBackground(new Color(83, 182, 255));
panel3.setBackground(new Color(255, 149, 66));
panel4.setBackground(new Color(239, 107, 140));
panel5.setBackground(new Color(17, 198, 99));
label1.setFont(new java.awt.Font("Serif", 1, 20));
label1.setForeground(Color.blue);
label1.setText("Select a language");
label2.setFont(new java.awt.Font("Dialog", 1, 24));
label2.setForeground(Color.black);
label2.setText("Good Evening");
label3.setFont(new java.awt.Font("Dialog", 1, 24));
label3.setForeground(Color.black);
label3.setText("Guten Abend");
label4.setFont(new java.awt.Font("Dialog", 1, 24));
label4.setForeground(Color.black);
label4.setText("Oodgay vening eay");
label5.setFont(new java.awt.Font("Dialog", 1, 24));
label5.setForeground(Color.black);
label5.setText("God Kvall");
choice1.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(ItemEvent e) {
choice1_itemStateChanged(e);
}
});
label6.setFont(new java.awt.Font("Dialog", 1, 24));
label6.setForeground(Color.black);
label6.setText("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");
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));
}
}
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.
import java.awt.*;
import javax.swing.UIManager;
import java.applet.Applet;
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.
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.
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.”
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.
In the status area at the bottom, the Diff page tells you how many
blocks of differences there are in your comparison.
Version control users To see all changes made to the repository since you started working,
select the original repository version in the From area and the file
version with the highest revision number in the To area.
2 Click the Refresh button.
This retrieves any new versions from the repository. There are none, so
your revision list won’t change.
3 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.
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
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
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
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
Index I-5