Tải bản đầy đủ (.pdf) (65 trang)

NetBeans the Definitive User Guide phần 1 pot

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (8.74 MB, 65 trang )

NetBeans: the Definitive Guide
Table of Contents
NetBeansinaNutshell
1.Introduction
IsNetBeansForYou? 1
Is This Book For You? 2
NetBeansandJava 2
WhatareJavaBeans? 2
The Core Concept of NetBeans 3
NetBeans as the "Visual JDK" 4
AllTheUsualFeatures 4
NetBeans as a tools platform 5
NetBeans as an open source community 6
A Steady Stream of Creativity 6
Don't Be Cross That This Book Is Cross-Platform 6
Contents of the Accompanying Sources 7
Licensing of the Code Examples in this Book 7
Writing Conventions in this Book 7
CommentsandQuestions 7
Acknowledgments 8
Reviewers 8
SimeonGreene 8
VaughnSpurlin 9
JackWoehr 9
JesseGlick 9
TimBoudreau 10
2. Getting and Installing the IDE
PlatformsandRequirements 11
What are the system requirements to run NetBeans? 11
Getting and Installing a JDK 12
TheJavaDevelopmentKit 12


Relationship of JDK to JRE 13
ObtainingtheJDK 13
WhichIDEDistribution? 14
InstallingBinaryDistributions 15
Building the IDE from Source (Simple builds) 16
What you'll need to build the IDE 16
Setting up and performing the build 17
Wheredideverythinggo? 18
How do I install a newly built version of NetBeans? 18
RunningtheIDE 19
Minimalenvironment 19
HowtoLaunchNetBeans 20
MultipleNetBeansusers 21
Troubleshooting 22
UpdatingtheIDEAutomatically 25
TheUpdateCenter 25
ConfiguringtheUpdateCenter 26
SetupWizard 27
You'renowrunningNetBeans 27
3.ConceptsandParadigms
NetBeans and the Java abstract model of computing 29
Explorer 30
Objects in the UI are represented by NetBeans nodes 30
Data objects, nodes, and the concept of actions and properties 31
Tabs in the Explorer and their purposes 38
NodeParadigms 44
Sometimes Explorer Gets Behind the Times 47
FilesystemsandtheCLASSPATH 48
CreatingPackagesandClasses 52
CreatingPackages 52

CreatingClasses 52
Services 55
Compilerservices 55
Executionservices 57
Debuggingservices 57
Workspaces 58
Editing 59
GUIEditing 59
Browsing 59
Running 59
Debugging 59
Persistenceacrosssessions 59
Using multiple instances of Explorer in different workspaces. 60
Using multiple instances of the Source Editor in different workspaces. 60
ProjectManagement 60
Managingmultipleprojects 61
Managing project builds using Ant 62
ObjectBrowser 63
Summary 66
4. Working with the Source Editor
Why learn a new editor? 68
OpeningtheSourceEditor 68
Contextmenus 69
ClosingtheSourceEditor 69
Codecompletion 69
Using (and Not Using) NetBeans Source Editor Code Completion 70
Updating the parser database to include new classes 71
Abbreviations 73
Editorcolorings 74
Shortcuts 75

Wordmatching 76
Indentation engines and code formatting 77
Automaticedits 77
OtherEditorFunctionality 78
Creating, editing, compiling and running a simple example 79
More on Customizing the Source Editor 82
5.Debugging
DebuggerTypes 83
BreakpointTypes 84
Addingandremovingbreakpoints 85
Settingwatches 89
StartingtheDebugger 89
TheDebuggerWindow 90
TheVariablesView 92
RemoteDebugginginNetBeans 93
Howtodebugremotely 93
Caveats 95
Advancedfeatures 96
6. Compilation and Execution Services
Using Custom Compilation and Execution Services 97
Creating and Customizing Internal Compilation Services 97
Creating and Customizing External Compilation Services 98
TheInternalExecutionService 103
Creating and Customizing External Execution Services 103
Associating Services With Java Files 104
Setting Default Services for Java Files 104
Setting Services for Specific Files 104
BuildingWithAnt 104
CreatingaBuildScript 104
ConfiguringtheAntModule 107

Executing and Compiling With Ant Scripts 108
WhyUseAnt? 108
7.Customizingtheenvironment
TheSetupWizard 109
GeneralNetBeansSettings 109
ModuleInstallation 112
UpdateCenter 112
TheToolsOptionsDialog 113
ConfiguringToolbars 114
ConfiguringMenus 116
ConfiguringEditors 117
ObjectTypeAssociations 117
EditorSettings 118
Commandlineoptions 126
Modules 128
InstallingModules 128
EnablingandDisablingModules 131
8. Using Source Control (CVS)
WhatisCVS? 133
The How, When and Why of CVS in NetBeans 135
WhentouseCVS 135
Where to get a client 135
How does NetBeans interact with CVS? 135
UsingGenericVCS 136
Using Command-Line CVS Support versus Built-in CVS 136
What parts of my project does CVS within NetBeans save? 137
Does NetBeans automatically add new files and packages I create to the repository? 137
How do I manipulate my NetBeans project directly with CVS outside of NetBeans? 137
MountingCVSsources 138
ExploringVersionedSources 138

Performing common CVS operations within the IDE 139
Checkout/Get 140
Checkin/Commit 141
AddandImport 141
Log 142
Diff 143
Update 144
UnexpectedResults 144
Spurious[Local]Designation 144
WhenAddingdirectories 145
WhenAddingbinaryfiles 145
Uncommon CVS operations within the IDE 145
Branching,MergingandTagging 146
NetBeans CVS and the Secure Shell (SSH) 146
Mounting and Customizing a Generic Versioning System 146
OneFinalTip 149
9.GUIBuilding
How to create a GUI frame or panel 151
How to add components to a GUI container 155
Configuring components with the Component Inspector 156
Buildingmenus 157
How to change and configure a container's Layout 157
WorkingwithBorders 158
Accessibility 158
CopyingaSourceObject 159
TheConnectionWizard 159
TheGridBagLayoutCustomizer 161
Addingeventhandlers 164
Using the Code Generation Properties 166
NetBeans made a mistake in code generation, what are the workarounds? 168

ContainerswithinContainers 171
BuildingComplexGUIs 171
10.JavaBeans
Why Should I Make Beans? 173
CreatingJavaBeans 173
CreatingaGUIComponent 174
Converting a GUI Component into a Bean 176
Adding an Event Set to a Bean 179
GeneratingaBeanInfoClass 181
AddingaDesign-TimeIcon 183
ComponentPalette 183
Adding a Category to the Component Palette 183
Adding a Bean to the Component Palette 184
ComponentPaletteProblems 185
11.UsingJavadoc
JavadocSupportinNetBeans 186
Mounting Javadocs in the Javadoc Repository 186
TheJavadocSearchTool 187
CreatingyourownJavadoc 190
TheAutoCommentTool 190
JavadocGeneration 193
12.WorkingwithXML
InstallingXMLSupport 196
Overview 197
Templates 197
BrowsingandEditing 197
GeneratingDocumentation 197
AccessingwithJava 197
Where'sXMLSchemaSupport? 198
XML Editors—Tree Editor and Text Editor 198

BeyondEditingXML 201
CheckingandValidatingXML 201
SettingtheNodeView 202
Generating Separate DTD from Existing XML 203
Generating Documentation to Help Humans Understand XML 204
GeneratingCSSfromDTD 206
Generating Java Classes to Handle XML 206
Generating a SAX Document Handler 206
Generating a DOM Tree Scanner 209
13.DevelopingWebApplications
Why the IDE Supports Web Application Development 214
How the IDE Provides Web Application Support 214
CreatingaWebApplication 214
TheFilesystemsView 216
TheWebProjectView 217
Working with JSP and HTML files 218
AdvancedWebApplicationsFeatures 221
ExecutingWebApplications 221
WorkingwithServlets 222
Packaging and Deploying Web Apps 223
DeployingWebApps 224
ConfiguringTomcat 224
A.Resources
CVSResources 227
CVSHome 227
GNU/BSD/OtherOperatingSystems 227
CVSGUIClients 228
JavaEnvironments 228
JavaTools 228
ApacheSoftwareFoundation 229

SecureShell(SSH)Resources 229
CygwinforWindows 229
NewsgroupsandMailingLists 230
WebSites 230
Organization of main NetBeans website 230
Mirrors 230
SunSites 230
Open source projects coded using NetBeans which include NetBeans design forms in the distribution
231
Java-oriented IDE's other than NetBeans 231
Bibliography
ExtendingNetBeans
Foreword—byJamesGosling
1.Introduction
Who Should Read this Book? 249
What’sDifferentaboutNetBeans? 250
The Core and the Open APIs 250
TheLicense 251
Open-Source 252
Thenetbeans.orgWebSite 252
NetBeansforBeanCounters 254
Getting and Installing the Open APIs Support Module 255
LifeisChange 256
Source code for the examples 256
2.HistoryofNetBeans
HumbleBeginnings 257
FirstSuccesses,FirstCosts 258
SunMeetsNetBeans 259
Open-Source,Fire-DrillStyle 260
NetBeansToday 260

3. Understanding the NetBeans APIs
DesignPhilosophyofNetBeans 261
Abstracting the Abstractions—the Open APIs 262
Modularity 262
Hierarchy,FilesandNodes 263
EverythingisaFile—Virtually 263
Mapping Files to Java Objects 264
TheSystemFilesystem 265
ModuleLayers 265
Layers in the System Filesystem 266
ExploringtheSystemFilesystem 267
Data Objects—Wrappers for Persistent Data 270
NetBeansandJavaBeans 270
Nodes—theApplicationasHierarchy 270
Presenting Nodes to the User—Explorer 271
User-LevelCustomization 273
Nodes in Action—Customizing the IDE without Writing Code 275
Modules—Overview 278
HowModulesAddFunctionality 278
How Modules Install Virtual Filesystem Layers 279
WhatModulesCanDo 279
DisablingModules 280
An Illustration—NetBeans with No Modules at All 280
Interacting with the IDE through Internal Execution 281
Setting the Status Bar Text 282
SettingtheCurrentWorkspace 283
4.TheOpenAPIs
The IDE’s Architecture and the APIs 284
APIs versus Core versus Modules 285
Service Provider Interfaces and Client APIs 286

Overview of the APIs and Their Purposes 286
Modules 287
Lookup and the Services API 294
Nodes 296
Datasystems 299
Explorer 299
Actions 304
Options 305
Compiler 305
Editor 306
WindowingSystem 307
Cookies 309
Execution 310
JavaHierarchy 310
Filesystems 311
Modules, JARs, and Class Loaders 312
Threading, Deadlocks, and How to Avoid Them 317
5. Developing Modules—the New Module Wizard
TheHelloWorldModule 319
Creating a Module Using the New Module Wizard 319
TheSourceFiles 320
6. Internals of the Running IDE
TheActivatedNode(s) 323
Cookies 324
A Peek under the Hood—Examining the Activated Nodes with the CurrentNodeViewer 325
Touring NetBeans with the Bean Browser 325
Data Objects, Nodes and Cookies 327
FilesystemsandtheRepository 327
Services 328
Lookup 329

Options 330
UIComponents 331
TopComponents,ModesandWorkspaces 331
Actions 336
Presenters 337
CustomPropertyEditors 337
Localization 337
Wizards 338
Jumping-offPlaces 338
Special Folders in the System Filesystem 339
7. Creating the QuickPanel Module
Abstractions Covered in this Chapter 342
Creating the Project Files Drop-Down 343
FilterNode—Filtering Which Children of a Node are Displayed 347
CreatingtheMethodsDrop-Down 349
ImprovingtheMethodsDrop-Down 350
CreatingtheModule 353
Creating a Container GUI Component 354
CreatingtheShowQuickPanelAction 354
Creating the XML Filesystem Layer 355
Creating and Populating the Module JAR 356
Building and Testing the Module 356
ALittleHomework 357
8.AMail-BasedFilesystem
Building a Mail Reader in the NetBeans Paradigm 358
Implementing MailFileSystem Using AbstractFileSystem and JavaMail 359
Creating a New AbstractFileSystem Implementation 359
MailFilesystem:AbstractFileSystem.Info 360
MailFilesystem:AbstractFileSystem.List 361
MailFilesystem:AbstractFileSystem.Change 362

MailFilesystem:AbstractFileSystem.Attr 363
OtherPartsofAbstractFileSystem 363
Creating Folder Objects for Attachments 366
Using FileSystem.Status Annotations to Mark Unread Messages 367
BeanInfo—DisplayingFilesystemProperties 369
Using the Wizard Framework to Set Up Mail Accounts 371
CreatingWizardClasses 371
The IMAP Mail Server Template Wizard 372
9. Creating the User Interface for the Mail Client
Creating a DataLoader for Messages 381
Displaying and Editing Simple Messages and Unnamed Attachments 382
HandlingMultipartMessages 386
Creating a Threaded Mail View Using Filter Nodes 387
Making a Basic Mail View 388
Making a Threaded Mail View as an Alternative 394
CreatingaMailWorkspace 400
10.ScoreFileSupport
Overview—FunctionalitytobeImplemented 406
Creating the Minicomposer Module—First Things 406
CreatingtheManifest 406
CreatingtheLayer 407
Creating a JAR File Using Ant 408
Creating a UniFileLoader and MultiDataObject for *.score Files 408
Creating an Editor Support for Scores 411
Creating a Fixed ExecCookie to Play Scores 414
CreatingaSimpleTemplate 417
11. Creating a Structural View of the Score
Creating a ScoreCookie to Represent a Sequence of Notes 419
Examples of State-Based Supports in the NetBeans APIs 420
CreatingaScoreSupport 421

Why a Document is Used 421
ImplementationofScoreSupport 422
LifecycleoftheScore 426
AnOpenSupport 426
CreatinganOpenCookieImplementation 427
Showing a GUI View of the ScoreCookie 429
Indicating Parse Errors on the Node 433
12.CompilingScores
What Does NetBeans Mean by “Compilation”? 437
CreatingtheCompilersThemselves 437
Creating and Using the Compiler Cookie 441
Displaying an Out-of-Date Badge on Score Icons 445
13.ExecutingScores
Execution Service Types—Internal and External 448
Creating the .au Player Executor 448
TheInternalPlayer 449
TheExternalPlayer 451
Registering the Players as Services 454
Creating Player Configuration Support (ExecSupport) 457
Creating a SystemOption for the Default Executor 461
14. Better Score Support in the Explorer
TheClipLengthProperty 467
Clearing the Cache and Firing Changes 469
Adding the Property to the Property Sheet 470
Representing Notes as Subnodes Using Children.Keys 470
Using Keys to Model Children 471
Being Lazy and Cleaning Up 473
CreatingtheSubnodes 474
Attaching the Children to the Parent 475
Permitting Subnodes to be Renamed or Deleted 476

DeletionofNotes 476
RenamingofNotes 477
Permitting Subnodes to be Added 479
Making Read/Write Properties on Subnodes 481
ReorderingSubnodes 484
Data Transfer—Cut, Copy, and Paste of Notes and Sequences 489
OverviewoftheTransferables 490
CuttingandCopying 491
Pasting 492
Drag&Drop 495
Converting Score # Text, Text # Score, Several Scores # One 495
15. Tuning Modules for Performance & Memory Footprint
Startup Performance vs. Runtime Performance 501
OperatingPrinciples 501
“Nobody Will Ever Use My Module” 501
What Does My Module Really Need to Do on Startup? 501
What are the Critical Paths? 502
Techniques 503
LazyInitialization 503
AvoidStaticInitializers 503
Avoid ModuleInstall Classes—Use XML Layers Instead 504
Partial Loading Considerations—InstanceCookie and InstanceDataObject 505
Use URLs Instead of CDATA Sections in XML Layers 505
Reduce the Number of Classes You Create 505
GUIComponents—WaitforaddNotify() 505
Using the addNotify() and removeNotify() Pattern Where Exposed by Non-GUI Classes 506
Use Weak and Soft References for Objects which May Not be Needed Forever 506
UseWeakListener 508
AvoidExcessiveEventFiring 508
AvoidOveruseofThreads 508

BatchingEvents 509
SwingPerformance 509
16. Producing Modules (Packaging & Distribution)
Versioning 511
Version Numbers and What They Mean 511
SpecifyingDependencies 512
ManagingInter-ModuleDependencies 513
UpgradingUserSettings 516
Settings History and Physical Format 517
UpgradeScenariosforSettings 518
What Happens When a Module is Disabled? 520
UserDevelopmentData 521
BundlingExtensionLibraries 521
ReferencingLibrarieswithClass-Path 522
UsingAutoloadLibraryModules 523
Ad-Hoc Resources and Module Installer Validation 525
InternationalizationandAccessibility 526
I18NandL10N 526
A11Y 528
JavaHelp—WritingandDistributing 529
CreatingaHelpSet 529
Adding a Help Set to NetBeans 531
AddingContextHelp 534
SeparatingHelpfromCode 535
SupportingUser-LevelJavaAPIs 535
SupplyingaParserDatabase 535
BundlingJavadoc 536
Adding to the Default Classpath 537
Templates 538
BeanInstallation 539

Creating the Module JAR File within the IDE 540
Creating a Build Script Using Ant 540
Producingthe.nbmFile 541
Publishing Using the Update Center 543
Using ErrorManager to Log Problems 545
Testing 547
17. Building Your Distribution of NetBeans
Do You Need Your Own Distribution? 549
Licensing 550
SelectingaBaseline 550
GettingtheSources 551
How to Customize the Build Process to Add Your Modules 552
Adding Modules to a “Stock” Distribution 553
CreatingPreconfiguredSettings 555
Branding 555
Implementing Branding on a Distribution 556
Simple Branding: Text Strings and Images 557
Configuration Branding: Menu Bar, Workspaces, … 558
AdvancedBranding:PatchingBehavior 564
A. A Tour of Existing Modules to Use and Learn From
Modules that Expose Functionality Your Module Might Need 569
TheXMLModules 569
TheEditor 570
Version Control—the VCS Core Module 570
RemoteFS 571
TheAntModule 571
TheJavaModule 571
DebuggerCore 572
J2EEServer 572
FormEditor 572

HTTPServerModule 572
ClassfileReaderModule 572
The Metadata Repository—a Whole Host of APIs 572
Socket-Based Editor Support—the External Editor Module 573
Incidental APIs, Utilities and Extensions 573
TheUtilitiesModule 573
APIExtensions(openidex) 573
Modules which Make Good Examples for Things You May Need to Implement 574
Annotations and Dynamic Editor Tool Tips—the Ant Module and the Debugger Core Module
574
Adding Information to the View of Java Sources—the Beans Module 574
Adding a Debugger Type—the Applet Module 574
Multiplexing DataObjects, and Complex Cut/Copy/Paste Support—the Properties Module 574
Working with Network Protocols to Access Files—JavaCVS and RemoteFS 574
Domain-Specific XML Support—the Tomcat and Ant Modules 575
Stretching the Limits—the Web Modules 575
Complex Syntax Coloring—the JSP Module 575
Multi-Stage Compilation—the JSP, RMI, and CORBA Modules 575
Bridging to an Entirely Different Build System—the Ant and Makefile Modules 575
Use of the Compiler Infrastructure for Non-Compilation Tasks—the JAR Packager Module 576
Execution—the Applet and JSP/Servlet Modules 576
Custom Hyperlinking in the Output Window—the Ant Module 576
Specifying Windows, Workspaces and Components Using XML—the Core Window System
and the Form Editor Module 576
Complex Work with MIMEResolvers and Multi-File DataObjects—the CPP Module 577
Cut/Copy/Paste—Data Transfer Support for Complex Elements—the Ant and Java Modules
577
Interconversion between Different Types of Clipboard Contents—JNDI, CORBA, and RMI 577
Integrating Other Programming Languages—the C++/Fortran, Scripting, and WebL Modules
577

Fancy Footwork with Nodes—the Java Module 578
Adding Nodes to the Runtime Tab in the Explorer—the RMI, CORBA, JNDI, and Database
ExplorerModules 578
The Bare Essentials of Non-Data-Driven Nodes—the System Properties Module 578
Wizards—the CORBA, Java and New Module Wizard Modules 578
Embedding Property Panels into Wizards—the Java Module 578
Complex Explorer Views—the Debugger Core Module 578
Enabling/Disabling Sets of Actions based on Context—the VCS Core Module 579
B.UsefulUtilityClasses
XMLUtilities 580
org.openide.xml.XMLUtil 580
org.openide.xml.EntityCatalog 580
Visual Components and Extensions to Standard Swing Components 580
LookupImplementations 581
Threading 581
Miscellaneous Utility Classes in org.openide.util 581
SerializationHelpers 582
C.FuturePlans
DeclarativeInstantiation 583
UniformLookup 583
DatasystemsII 584
TheLooksAPI 584
DeclarativeActions 585
Deprecation of IDE-Specific Functionality in the Open APIs 585
TheMetadataRepository 585
Standards Employed by the MDR 586
ProjectSupport 587
D. Working with Open-Source and NetBeans
Practices 589
Governance 589

Consensus 590
HowtoGetInvolved 595
The Lifecycle of Module Development 600
Resources 602
CVS(ConcurrentVersioningSystem) 602
Projects 602
MailingLists 602
Issuezilla 603
Interacting Effectively on Mailing Lists 604
E. Additional Modules and Where to Find Them
Open-Source Modules Available via the Update Center 606
The Modules Marketplace on Flashline 606
IDEs that are Distributions of the NetBeans IDE 608
Open-Source Application Projects Based on NetBeans 609
Commercial Applications Built on the NetBeans Platform 609
Commercial Modules Available for NetBeans 610
Should You Create Your Own Update Server? 612
Glossary
NetBeans in a Nutshell
NetBeans in a Nutshell
Copyright © 2001, 2002 O’Reilly & Associates, Inc.
Warning
This is a DRAFT IN PROGRESS and should not be distributed freely! Except with special permission, only O’Reilly employees, authors,
and reviewers should be reading this manuscript at this stage.

Table of Contents
1.Introduction
IsNetBeansForYou? 1
Is This Book For You? 2
NetBeansandJava 2

WhatareJavaBeans? 2
The Core Concept of NetBeans 3
NetBeans as the "Visual JDK" 4
AllTheUsualFeatures 4
NetBeans as a tools platform 5
NetBeans as an open source community 6
A Steady Stream of Creativity 6
Don't Be Cross That This Book Is Cross-Platform 6
Contents of the Accompanying Sources 7
Licensing of the Code Examples in this Book 7
Writing Conventions in this Book 7
CommentsandQuestions 7
Acknowledgments 8
Reviewers 8
SimeonGreene 8
VaughnSpurlin 9
JackWoehr 9
JesseGlick 9
TimBoudreau 10
2. Getting and Installing the IDE
PlatformsandRequirements 11
What are the system requirements to run NetBeans? 11
Getting and Installing a JDK 12
TheJavaDevelopmentKit 12
Relationship of JDK to JRE 13
ObtainingtheJDK 13
WhichIDEDistribution? 14
InstallingBinaryDistributions 15
Building the IDE from Source (Simple builds) 16
What you'll need to build the IDE 16

Setting up and performing the build 17
Wheredideverythinggo? 18
How do I install a newly built version of NetBeans? 18
RunningtheIDE 19
Minimalenvironment 19
HowtoLaunchNetBeans 20
MultipleNetBeansusers 21
Troubleshooting 22
UpdatingtheIDEAutomatically 25
TheUpdateCenter 25
ConfiguringtheUpdateCenter 26
SetupWizard 27
You'renowrunningNetBeans 27
3.ConceptsandParadigms
NetBeans and the Java abstract model of computing 29
Explorer 30
Objects in the UI are represented by NetBeans nodes 30
Data objects, nodes, and the concept of actions and properties 31
Tabs in the Explorer and their purposes 38
NodeParadigms 44
Sometimes Explorer Gets Behind the Times 47
FilesystemsandtheCLASSPATH 48
CreatingPackagesandClasses 52
CreatingPackages 52
CreatingClasses 52
Services 55
Compilerservices 55
Executionservices 57
Debuggingservices 57
Workspaces 58

Editing 59
GUIEditing 59
Browsing 59
Running 59
Debugging 59
Persistenceacrosssessions 59
Using multiple instances of Explorer in different workspaces. 60
Using multiple instances of the Source Editor in different workspaces. 60
ProjectManagement 60
Managingmultipleprojects 61
Managing project builds using Ant 62
ObjectBrowser 63
Summary 66
4. Working with the Source Editor
Why learn a new editor? 68
OpeningtheSourceEditor 68
Contextmenus 69
ClosingtheSourceEditor 69
Codecompletion 69
Using (and Not Using) NetBeans Source Editor Code Completion 70
Updating the parser database to include new classes 71
Abbreviations 73
Editorcolorings 74
Shortcuts 75
Wordmatching 76
Indentation engines and code formatting 77
Automaticedits 77
OtherEditorFunctionality 78
Creating, editing, compiling and running a simple example 79
More on Customizing the Source Editor 82

5.Debugging
DebuggerTypes 83
BreakpointTypes 84
Addingandremovingbreakpoints 85
Settingwatches 89
StartingtheDebugger 89
TheDebuggerWindow 90
TheVariablesView 92
RemoteDebugginginNetBeans 93
Howtodebugremotely 93
Caveats 95
Advancedfeatures 96
6. Compilation and Execution Services
Using Custom Compilation and Execution Services 97
Creating and Customizing Internal Compilation Services 97
Creating and Customizing External Compilation Services 98
TheInternalExecutionService 103
Creating and Customizing External Execution Services 103
Associating Services With Java Files 104
Setting Default Services for Java Files 104
Setting Services for Specific Files 104
BuildingWithAnt 104
CreatingaBuildScript 104
ConfiguringtheAntModule 107
Executing and Compiling With Ant Scripts 108
WhyUseAnt? 108
7.Customizingtheenvironment
TheSetupWizard 109
GeneralNetBeansSettings 109
ModuleInstallation 112

UpdateCenter 112
TheToolsOptionsDialog 113
ConfiguringToolbars 114
ConfiguringMenus 116
ConfiguringEditors 117
ObjectTypeAssociations 117
EditorSettings 118
Commandlineoptions 126
Modules 128
InstallingModules 128
EnablingandDisablingModules 131
8. Using Source Control (CVS)
WhatisCVS? 133
The How, When and Why of CVS in NetBeans 135
WhentouseCVS 135
Where to get a client 135
How does NetBeans interact with CVS? 135
UsingGenericVCS 136
Using Command-Line CVS Support versus Built-in CVS 136
What parts of my project does CVS within NetBeans save? 137
Does NetBeans automatically add new files and packages I create to the repository? 137
How do I manipulate my NetBeans project directly with CVS outside of NetBeans? 137
MountingCVSsources 138
ExploringVersionedSources 138
Performing common CVS operations within the IDE 139
Checkout/Get 140
Checkin/Commit 141
AddandImport 141
Log 142
Diff 143

Update 144
UnexpectedResults 144
Spurious[Local]Designation 144
WhenAddingdirectories 145
WhenAddingbinaryfiles 145
Uncommon CVS operations within the IDE 145
Branching,MergingandTagging 146
NetBeans CVS and the Secure Shell (SSH) 146
Mounting and Customizing a Generic Versioning System 146
OneFinalTip 149
9.GUIBuilding
How to create a GUI frame or panel 151
How to add components to a GUI container 155
Configuring components with the Component Inspector 156
Buildingmenus 157
How to change and configure a container's Layout 157
WorkingwithBorders 158
Accessibility 158
CopyingaSourceObject 159
TheConnectionWizard 159
TheGridBagLayoutCustomizer 161
Addingeventhandlers 164
Using the Code Generation Properties 166
NetBeans made a mistake in code generation, what are the workarounds? 168
ContainerswithinContainers 171
BuildingComplexGUIs 171
10.JavaBeans
Why Should I Make Beans? 173
CreatingJavaBeans 173
CreatingaGUIComponent 174

Converting a GUI Component into a Bean 176
Adding an Event Set to a Bean 179
GeneratingaBeanInfoClass 181
AddingaDesign-TimeIcon 183
ComponentPalette 183
Adding a Category to the Component Palette 183
Adding a Bean to the Component Palette 184
ComponentPaletteProblems 185
11.UsingJavadoc
JavadocSupportinNetBeans 186
Mounting Javadocs in the Javadoc Repository 186
TheJavadocSearchTool 187
CreatingyourownJavadoc 190
TheAutoCommentTool 190
JavadocGeneration 193
12.WorkingwithXML
InstallingXMLSupport 196
Overview 197
Templates 197
BrowsingandEditing 197
GeneratingDocumentation 197
AccessingwithJava 197
Where'sXMLSchemaSupport? 198
XML Editors—Tree Editor and Text Editor 198
BeyondEditingXML 201
CheckingandValidatingXML 201
SettingtheNodeView 202
Generating Separate DTD from Existing XML 203
Generating Documentation to Help Humans Understand XML 204
GeneratingCSSfromDTD 206

Generating Java Classes to Handle XML 206
Generating a SAX Document Handler 206
Generating a DOM Tree Scanner 209
13.DevelopingWebApplications
Why the IDE Supports Web Application Development 214
How the IDE Provides Web Application Support 214
CreatingaWebApplication 214
TheFilesystemsView 216
TheWebProjectView 217
Working with JSP and HTML files 218
AdvancedWebApplicationsFeatures 221
ExecutingWebApplications 221
WorkingwithServlets 222
Packaging and Deploying Web Apps 223
DeployingWebApps 224
ConfiguringTomcat 224
A.Resources
CVSResources 227
CVSHome 227
GNU/BSD/OtherOperatingSystems 227
CVSGUIClients 228
JavaEnvironments 228
JavaTools 228
ApacheSoftwareFoundation 229
SecureShell(SSH)Resources 229
CygwinforWindows 229
NewsgroupsandMailingLists 230
WebSites 230
Organization of main NetBeans website 230
Mirrors 230

SunSites 230
Open source projects coded using NetBeans which include NetBeans design forms in the distribution
231
Java-oriented IDE's other than NetBeans 231
Bibliography
List of Figures
2.1. NetBeans Minimum Requirements on Several Popular Platforms 12
2.2. Summary of tradeoffs between NetBeans releases 14
5.1.DebuggerTypes 83
5.2.SettingBreakpoints 86
5.3.AddBreakpointdialog 87
5.4. Set Breakpoint Type Variable 88
5.5.StartingtheDebugger 90
5.6.DebuggerWindow 91
5.7.ModifyingaVariable 92
5.8. The Attach dialog box 94
5.9.TheDebuggerwindow 95
6.1. The Internal Compiler Service 97
6.2. JDK 1.1 External Compilation Service 99
6.3. Environment variables property editor 100
6.4. External Process configuration dialog 102
6.5. The JDK External Compiler with the nowarn argument 102
6.6. An Ant project build script 105
6.7. Adding a new Ant task 105
6.8.AntHelppage 106
7.1. The first pane of the Setup Wizard 109
7.2. An editor window with a filesystem explorer docked on the left 111
7.3. The second pane of the Setup Wizard 112
7.4. The third pane of the Setup Wizard 112
7.5.Toolbaroptions 115

7.6. Changing the toolbar button order 115
7.7. Creating and editing menus 116
7.8.Globalkeybindings 118
7.9. The fonts and colors editor 120
7.10.Thecolorpicker 121
7.11.Thefontpicker 123
7.12.Recordingamacro 124
7.13.Editingmacros 125
7.14.IndentationEngine 126
7.15. IDE command line options 127
7.16. The Auto Update Center - Pane 1 128
7.17. Installing modules from the web 129
7.18. Completing Installation of modules for the web 130
7.19.Installingmodulesmanually 131
8.1. Summary of how CVS extends RCS 134
8.2. The Version Explorer window 138
8.3. The GUI style CVS options dialog for an update 140
8.4. Browsing the CVS log of a source tree 142
8.5. Performing a CVS diff operation 144
8.6. Pulling down the Versioning menu 146
8.7. The Versioning Window for CVS 147
8.8. Advanced options for the CVS Versioning window 147
8.9. Editing generic versioning commands 148
9.1. Creating the GuiDemoBasic package 152
9.2. Creating the AddStrings JFrame 154
9.3. The NetBeans Form Editor 155
9.4. The GuiBasicDemo example being tested 156
9.5. Testing the form with a FlowLayout 156
9.6.GuiDemoBasicusingGridLayout 157
9.7. The Connection Mode button 160

9.8. Testing after linking events 160
9.9. A GridBaglayout example, with 3 rows and 5 columns 161
9.10.GridBagLayoutCustomizerdialog 162
9.11. Generating an ExitItem event 165
9.12. Selecting an event handler 165
9.13. The AddStrings example running 166
9.14.Addingpost-creationcode 167
9.15. Creating a custom template category 169
10.1.CopyingAddStringscomponents 174
10.2. Testing the AddStrings Bean 178
10.3. The BeanInfo Editor dialog box 182
10.4. The AddStrings Bean icon 183
10.5. Creating a new component palette category 184
10.6. The AddStrings Bean in the component palette 184
11.1.TheJavadocRepository 186
11.2. The Javadoc Search Tool 187
11.3. Select the text to search for in Javadocs and hit Ctrl+F1 189
11.4. The search tool starts with your text and matching results. 189
11.5. The Javadoc Auto-Commenting Tool 191
11.6.AddingJavadocLinks 194
12.1. Installing modules for XML support 196
12.2. The XML tree editor and text editor 198
12.3. Adding a new attribute 199
12.4. DTD and data nodes 202
12.5. DTD separated from an XML document 203
13.1. A web application directory structure in Filesystem view 215
13.2. The Web Project View 217
13.3. Adding a new JSP 219
13.4. JSP Page in Browser 221
13.5. Creating a new servlet 222

13.6. Selecting a default application server 224
13.7. Configuring The Tomcat Server 225
List of Tables
5.1. Debugger Types that come with NetBeans 3.3
5.2. Runtime events that can be used to trigger a breakpoint define the following Breakpoint Types
5.3.DebugMenuOptions
6.1. Configuration Properties for the Internal Compilation Service.
6.2. Expert Configuration Properties for the Internal Compilation Service
6.3. Configuration Properties for the External Compilation Service
6.4. Expert Configuration Properties for the External Compilation Service
6.5. Configuration Properties for the External Execution Service
6.6. Expert Configuration Properties for the External Execution Service
6.7. Properties for Ant Settings
6.8. Properties for the Ant Compiler
7.1.ObjectTypes
7.2. Java Indentation Engine Properties
7.3. IDE Command Line Arguments
9.1. Text and Editable Property Settings for AddStrings Components
9.2. Names for AddStrings Components
9.3. Menu Item Properties for AddStrings
9.4.CustomizerProperties
10.1. Setting wizard properties for the AddStrings Bean
10.2.Settingcomponentdirections
10.3. Setting wizard properties for event listeners
11.1. Javadoc Search Tool Buttons
11.2.MethodFilteringButtons
11.3.ExternalJavadocExecutor
11.4.ExternalJavadocExecutor
11.5.AdditionalDocletProperties
12.1. Printing Element Names in Inventory_InventoryScanner

12.2. Printing Attribute Values in Inventory_InventoryScanner
12.3. Printing Element Data in Inventory_InventoryScanner
12.4. Modifying Attribute Values in Inventory_InventoryScanner
13.1. Features Added by the JSP/Servlet Module
13.2. Templates for Creating Web Application files
List of Examples
3.1. Example 3-1. A NetBeans form file 36
5.1. Multithreaded Example for Debugging Demo—ThreadedCounter.java 85
10.1. Code in AddStrings JFrame needed for the new Bean 175
10.2. Code Needed in Getter and Setter methods for AddStrings Bean 177
10.3. Event Handler Methods in AddStrings Bean 178
10.4. Code Needed for Events in AddStrings Bean 179
10.5.BeginningofASTest3 180
10.6. propertyChange Method in ASTest3 180
10.7. ActionPerformed Event Handlers in ASTest3 181
10.8. initComponents method for ASTest4 185
12.1. Inventory.xml after adding elements and attributes 200
12.2. DTD text for Inventory.xml 201
12.3. HTML documentation for Inventory.xml 205
12.4. Cascading Stylesheet for Inventory.xml 206
12.5. main method for Inventory_InventoryParser 207
12.6. characters method for Inventory_InventoryHandlerImpl 207
12.7. startElement method for Inventory_InventoryHandlerImpl 208
12.8.OutputfromInventory_InventoryHandlerImpl 208
12.9. main method for Inventory_InventoryScanner 209
12.10. visitElement_Part method with all changes applied 210
12.11. main method with all changes applied 211
12.12. import statements for Transformer references 212
12.13.OutputfromInventory_InventoryScanner 212
13.1. Source Listing for index.jsp 220

Chapter 1. Introduction
Table of Contents
IsNetBeansForYou? 1
Is This Book For You? 2
NetBeansandJava 2
WhatareJavaBeans? 2
The Core Concept of NetBeans 3
NetBeans as the "Visual JDK" 4
AllTheUsualFeatures 4
NetBeans as a tools platform 5
NetBeans as an open source community 6
A Steady Stream of Creativity 6
Don't Be Cross That This Book Is Cross-Platform 6
Contents of the Accompanying Sources 7
Licensing of the Code Examples in this Book 7
Writing Conventions in this Book 7
CommentsandQuestions 7
Acknowledgments 8
Reviewers 8
SimeonGreene 8
VaughnSpurlin 9
JackWoehr 9
JesseGlick 9
TimBoudreau 10
Is NetBeans For You?
Is NetBeans for you? The algorithm for answering this question, is:
1. Determine what NetBeans does.
2. Decide if that functionality is for you.
NetBeans is first and foremost a well-crafted open source programmer's integrated development environment (IDE). It's
powerful, it's useful, it's extensible, it's open and it's free.

Sometimes integrated development environments are misunderstood as intended to make Java programming easier.
You know already, though, that advanced tools don't save work so much as they make the same amount of work yield
more effective results.
That's what NetBeans does; it allows you to trade one set of practices for another. The practices which NetBeans im-
poses are fully as intricate as your current development practices. More intricate, perhaps, because if you are a real pro-
grammer, you will wish to supplement your work style with NetBeans rather than attempting to use NetBeans to com-
pletely replace your current work style. The practice of NetBeans development is not easier. It's just more effective
than what you were doing before NetBeans. You get more done with NetBeans.
Chapter 1. Introduction
1

×