Working with code
The JBuilder Editor has many powerful features that enhance your ability to work with text and code. The Editor, in conjunction with JBuilder's three-paned AppBrowser, provides many editing and navigation functions. You can view multiple files in the AppBrowser, and easily find the specific lines of text and source code you want to modify.
This chapter explains how to perform the following editing tasks:
This chapter also provides information on:
Setting Editor options
You can customize the editing environment in JBuilder to suit your own preferences using the Environment Options dialog box. The Environment Options dialog has the following tabbed pages related to editing:
To open the Environment Options dialog box,
- Right-click in the Source pane of the AppBrowser and choose Properties.
-or-
- Choose Tools|IDE Options.
The Editor page
Use the Editor page of the Environment Options dialog box to:
- Set Editor options
- Configure editing commands
- Choose block indents
- Determine the Edit|Undo limit
- Set tab stops
- Choose syntax extensions for syntax highlighting
You can select your own preferences for keystroke behavior, or you can use the Editor SpeedSettings list box to choose from four default keyboard mappings:
- Default
- Classic
- BRIEF
- Epsilon
See also:
Context-sensitive help: Editor page of the Environment Options dialog box
The Display page
Use the Display page of the Environment Options dialog box to:
- Select display options
- Change the Editor font
- Choose keyboard mappings such as BRIEF, Epsilon, and Classic
See also:
Context-sensitive help: Display page of the Environment Options dialog box
The Colors page
Use the Colors page of the Environment Options dialog box to specify the colors of all the elements of your source code and text. You can specify colors for all of the code elements listed in the Element list box, such as numbers, text, comments, and identifiers.
You can select either your own custom colors, or you can choose from the following default SpeedSettings:
- Default
- Classic
- Twilight
- Ocean
On the Colors page, you can also specify format attributes for each element of your code, including:
See also:
Context-sensitive help: Colors page of the Environment Options dialog box
Displaying the Editor
To display the Editor, first navigate to the text file you want to view or modify. Then click the Source tab at the bottom of the Content pane The file is displayed in the Content pane, ready for editing.
Navigating to text files
To select files to view or modify, first select the file in the Navigation pane, in the upper left part of the AppBrowser.
When you select a file in the Navigation pane, two panes display the file.
- The Content pane, on the right, shows the text that is in the file and enables you to edit files.
- The Structure pane, in the lower left, enables you to navigate quickly through a file by selecting a variable or method in the file.
With both the Structure and Navigation panes, you can easily navigate to any text or code associated with any file, component, class, method, event or property in an application.
See also:
Managing projects with the AppBrowser
Drilling down into ancestor classes
Moving around in text files
Ways to move around in text
|
Action |
Feature |
|
Select variables and methods to navigate to |
The Structure pane, in the lower left of the AppBrowser |
Go to a specific line number |
Search|Go To Line Number |
Browse through a class, interface or package |
Search|Browse Symbol |
Find and replace text |
Search|Find and Search|Replace |
Search for text incrementally, as you type in the search string |
Search|Incremental Search |
Search for text across all files in selected path(s) |
Search|Search Source Path |
Set bookmarks and return to them |
Key combinations, listed in keymap files |
|
Moving through the structure of a file
To move through a text file, you can:
- Click method names and variable names in the Structure pane (for Java files).
- Click headings and links in the Structure pane (for HTML files).
The Content pane displays the source file. The line of source code or text that matches the selected object is highlighted.
See also:
Drilling down into ancestor classes
Going to a specific line number
You can go to a specific line number in your text by using the Go To Line Number dialog box, which prompts you for the line number to go to. The current line and character number where your cursor is placed appear in the dialog box when it opens.
To move the cursor to a specific line number in your text,
- Choose Search|Go to Line Number.
The Go To Line Number dialog is displayed.
- Enter the number of the source code line you wish to go to in the Enter New Line Number list box,.
- Click OK.
Go to Line Number dialog box
See also:
Context-sensitive help: Go To Line Number dialog box
Browsing the source code for a language keyword
You can browse to the code for a specific symbol in the Structure pane by using the right click menu or the Browse Symbol command. Symbols, or keywords, include:
- Class name
- Interface name
- Event name
- Method name
- Property name
- Package name
To browse to the code for a specific symbol,
- Select the symbol and choose Search|Browse Symbol or right-click the symbol and choose Browse Cursor at Symbol.
The Browse Goto dialog is displayed.
- Enter the name of the class, interface or package you want to browse.
- Click OK.
Browse GoTo dialog box
See also:
Context-sensitive help: Browse Goto dialog box
Using bookmarks
You can set bookmarks to lines of text that you return to frequently. Once you have set a bookmark to a line in a source file, you can easily return to that line by using keyboard commands. You can also remove a bookmark when you no longer need it.
Use keyboard shortcuts to place bookmarks in text. To place a bookmark, put your cursor at the line you want to return to, and press the keystroke appropriate for the keyboard mapping you are using.
See also:
Bookmark operations using the Default keymapping
Bookmark operations using the Brief keymapping
Bookmark operations using the Epsilon keymapping
Bookmark operations using the Classic keymapping
Working with multiple source files
You can edit up to three files in the AppBrowser by selecting one file in the Project Browser, another in the Opened Files Browser, and another in the Directory Browser. The browsers are accessed via the tabs displayed at the bottom of the Structure pane.
You can open additional AppBrowsers for individual files in the Opened file list with the View|New Browser command. In the AppBrowser for a single file, the leftmost tab is "Browser" rather than "Project."
When working with multiple AppBrowsers, you can use View|Window list to switch between them.
See also:
AppBrowser modes
Maximizing the Content pane to full-screen
To fully maximize the Content pane,
- Minimize the Main window by clicking the Restore button in the upper right corner of the window.
- Expand the Content pane by selecting View|Toggle Curtain.
- Maximize the Content pane to full screen by clicking its Maximize button.
The Content pane now occupies the entire screen. The Structure pane and Navigation pane are hidden.
Related keyboard shortcuts
|
Shortcut |
Description |
|
Alt+Space,R |
Restores the size of the Content pane |
Alt+Z |
Shows or hides the left panes (View|Toggle Curtain) |
Editing text
You can edit text using either menu commands or keystrokes. The Editor enables you to perform the following standard editing commands:
- Cut, copy, paste and delete
- Undo and redo
Cutting, copying, pasting, and deleting text
You use the following commands for cutting, copying, pasting and deleting text:
|
Command |
Description |
|
Edit|Cut |
Cuts selected text and moves it to the clipboard. |
Edit|Paste |
Inserts text in the clipboard to a new location. |
Edit|Copy |
Copies the selected text to the clipboard. |
Edit|Delete |
Deletes the selected text. |
|
Undoing and redoing editing actions
You can use the Undo command to undo your last keystrokes, action or deletion. Undo multiple successive actions by continuing to use the Undo command. You can specify a limit to the number of previous actions you can undo on the Editor page of the of the Environment Options dialog box. Undo enables you to reverse entire block operations.
To undo your last keystrokes, action or deletion,
- Choose Edit|Undo, or
- Press Ctrl+Z.
To reverse an undo,
- Choose Edit|Redo, or
- Press Shift+Ctrl+Z.
See also:
Context-sensitive help: Editor page of the Environment Options dialog box
Finding and replacing text
The Editor lets you specify the full string you want to find before searching, or you can search for text as you type by using the Editor's incremental search function.
You can search for literal text, or you can use regular expressions to find characters or words.
Finding specific text
To find specific text,
- Choose Search|Find or press Ctrl+F.
The Find Text dialog box is displayed.
- Specify text you want to locate.
- Set options that affect the search.
- Click OK.
Find Text dialog
See also:
Context-sensitive help: Find Text dialog box
Replacing text
To replace text,
- Select Search|Replace or press Ctrl+R.
The Replace Text dialog is displayed.
- Specify text you want to search for and then replace with other text.
- Click OK.
Replace Text dialog
See also:
Context-sensitive help: Replace Text dialog box
Searching incrementally as you specify a search string
You can search for text as you type by performing an incremental search. Suppose you are searching for "WidgetConstructorScrollbar". When you type "w", the word "wizard" might be found, and highlighted in the Source pane, but because that's not what you're looking for, you'd type some more characters. When you have typed "widget", the word "WidgetEvaluator" might be found. Finally, when you have typed "widgetc", the correct string might be found.
Note: The search begins from the cursor's location in the file. It does not start from the beginning of the file.
To perform an incremental search,
- Choose Search|Incremental Search or press Ctrl+E.
- Begin typing the string you want to find.
The status line of the bottom of the AppBrowser reads "Searching For:" and displays each letter as you type it.
- Continue typing in the rest of the search string until the full string you want is found.
- Press the Enter or Escape key to stop the search.
Incremental Search keystrokes
|
Option |
Effect |
|
Backspace |
Remove the last character from the search string and move to the previous match. |
F3 |
Repeat search (Default key binding) |
Ctrl+L |
Repeat search (Classic key binding) |
Ctrl+S |
Repeat search (Epsilon key binding) |
Shift+F5 |
Repeat search (Brief key binding) |
|
Searching for text across files in a selected path or paths
To search for text across file paths,
- Choose Search|Search Source Path.
The Search Source Path dialog is displayed.
- Enter the search string.
- Check Case Sensitive for a case-sensitive search.
- Check Recurse Subdirectories to search all subdirectories in the selected directories.
- Click Add to add a path to the search list.
The Select Directory dialog is displayed, where you choose the directories to search.Click OK when you've selected the directories to search.
- Select the path and click Remove to remove a path from the search list.
- Click Start to start the search.
When the search is complete, a new AppBrowser tab is displayed to the right of the Directory tab at the bottom of the Structure pane. This tab lists the files that contain the selected search string. If there are no matches, the tab is empty. To remove the tab, right-click it and choose Remove Search Tab.
Search Source Path dialog
See also:
Context-sensitive help: Search Source Path dialog box
Recording keystrokes
The Record Keystroke feature is a useful tool for editing text and code. You can record and playback keystrokes to automate keyboard tasks. The keystrokes you record are available to playback until you record a new set or close the Editor.
The keystroke command used to record keystrokes depends on which keyboard emulation you have selected as the default in the Editor. (This feature is not available when using the Epsilon keyboard emulation.)
Keystrokes for Record Keystroke feature
|
Keystroke |
Keyboard Emulation |
|
Ctrl+Shift+R |
Default, Classic |
F7 |
Brief |
|
To record keystrokes,
- Place the cursor at the location where you want to begin recording keystrokes.
- Type the keyboard command for recording keystrokes (see previous table).
The status bar at the bottom of the AppBrowser now says "Recording."
- Type the keystrokes you want to save to play back.
- Type the same command again to stop recording keystrokes.
The Playback Keystroke feature
|
Keystroke |
Keyboard Emulation |
|
Ctrl+Shift+P |
Default, Classic |
F8 |
Brief |
|
To playback keystrokes,
- Insert the cursor at the place you want your keystrokes played back.
- Type the command to playback keystrokes (see above table).
The recorded keystrokes are played back.
Recorded keystrokes can be played back in a different AppBrowser than the one in which they were typed. If, for example, you have more than one project open at the same time, and you record keystrokes in the Content pane of one AppBrowser, you can switch to another project and play back the recorded keystrokes in its Content pane.
Automatic code generation with wizards
JBuilder provides file and utility wizards that automatically generate code. This section provides brief overviews of coding tasks that you can quickly accomplish with wizards.
Creating a project
A Java development project holds all the files for your program, whether your objective is a Web applet or a complete application.
To create a project,
- Choose File|New, then Project.
The Project wizard is displayed.
- In the File box, enter the name of the project file. The default extension for a JBuilder project is .JPR.
- Complete the other fields as needed. The Title, Author, Company and Description are not required.
- Click Finish when you're done.
The Project wizard automatically builds a project file in the specified package directory, ready for files to be added. The project is displayed in the AppBrowser.
See also:
Creating a new project using the Project wizard
Context-sensitive help: Project wizard
Creating an application
A Java application is a stand-alone program that is similar to programs created using C++ or other programming languages. A Java application does not need to be run in an HTML browser nor is it subject to the security measures imposed on Java applets.
To create an application,
- Choose File|New, then Application.
The Application wizard is displayed.
Note: If you do not have an active project, the Project wizard is loaded first, prompting you to create a project. When a project is active, the Application wizard is displayed.
- In the first page of the wizard, enter the package, class and file name, and choose the application style. Click Next when you're done.
- In the second page, enter the default frame's class and file name, then choose its style. Click Finish.
JBuilder creates the new application shell, displayed as a .java source file in the Navigation pane. The application has a Frame, so you can immediately use the visual design tools to create the UI.
See also:
Using the Application wizard to start a project
Context-sensitive help: Application wizard
Creating an applet
An applet is a program that is intended to be embedded in an HTML page and run in an HTML browser or applet viewer. Various security measures are imposed on an applet. For example, an applet cannot perform input/output operations on a user's system and therefore cannot read or write files or transmit computer viruses.
To create an applet,
- Choose File|New, then Applet.
The Applet wizard is displayed. If you do not have an active project, the Project wizard is loaded first, prompting you to create a project. When a project is active, the Applet wizard is displayed.
- On the first page of the wizard, enter the package, class and file name, and choose the applet style. Click Next when you're done.
- On the second page, set the applet parameters, including the name, type, variable, description and default name. Click Next to move to the third page.
- On the wizard's last page, enter the specifications for the HTML page in which the applet will be embedded. Click Finish.
JBuilder creates a minimal applet and an HTML file which contains the applet. The applet is displayed as a .java source file in the Navigation pane.
See also:
Using the Applet wizard to start a project
Running applets
Context-sensitive help: Applet wizard
Creating a frame
A frame is a top-level window with a border and a title. It has standard window controls such as a control menu, buttons to minimize and maximize the window, and controls for resizing the window.
To create a frame,
- Choose File|New, then Frame.
The New Frame wizard is displayed. If you do not have an active project, the Project wizard is loaded first, prompting you to create a project. When a project is active, the New Frame wizard is displayed.
- In the New Frame wizard, enter the name of the package and class. The file name is automatically filled in for you; it is assigned the same name as the class and is saved to the package directory.
- Click OK to create the frame and its source code.
The frame is displayed as a .java source file in the Navigation pane.
See also:
Windows and panels
Context-sensitive help: New Frame wizard
Creating a dialog
A dialog is a pop-up window with a border and a title. Dialogs are typically used for user input to your application.
To create a dialog,
- Choose File|New, then Dialog.
The New Dialog wizard is displayed. If you do not have an active project, the Project wizard is loaded first, prompting you to create a project. When a project is active, the New Dialog wizard is displayed.
- In the New Dialog wizard, enter the name of the dialog's package and class. The file name is automatically filled in for you; it is assigned the same name as the class and is saved to the package directory.
- Click OK to create the dialog and its source code.
The dialog is displayed as a .java source file in the Navigation pane.
See also:
Windows and panels
Context-sensitive help: New Dialog wizard
Creating a panel
A panel is a UI container that groups components, like buttons, checkboxes and text fields. A panel does not have a border or a title. Typically, a panel is embedded within a dialog or frame.
To create a panel,
- Choose File|New, then Panel.
The New Panel wizard is displayed. If you do not have an active project, the Project wizard is loaded first, prompting you to create a project. When a project is active, the New Panel wizard is displayed.
- In the New Panel wizard, enter the name of the panel's package and class. The file name is automatically filled in for you; it is assigned the same name as the class and is saved to the package directory.
- Click OK to create the panel and its source code.
The panel is displayed as a .java source file in the Navigation pane.
See also:
Windows and panels
Context-sensitive help: New Panel wizard
Creating a data module
A data module is a container for objects that comprise your data source.
To create a data module,
- Choose File|New, then Data Module.
The New DataModule wizard is displayed. If you do not have an active project, the Project wizard is loaded first, prompting you to create a project. When a project is active, the New DataModule wizard is displayed.
- In the New DataModule wizard, enter the name of the data module's package and class. The file name is automatically filled in for you; it is assigned the same name as the class and is saved to the package directory.
- Click OK to create the data module.
The data module is displayed as a .java source file in the Navigation pane.
See also:
Context-sensitive help: New DataModule wizard
Creating a class
A class is an encapsulated collection of data and methods that operate on the data. If you want to design your class with JBuilder's visual design tools, you should use the Application or Applet wizard to create your project and class files.
To create a class,
- Choose File|New, then Class.
The New Java File wizard is displayed. If you do not have an active project, the Project wizard is loaded first, prompting you to create a project. When a project is active, the New Java File wizard is displayed.
- In the New Java File wizard, enter the name of the package and class. The file name is automatically filled in for you; it is assigned the same name as the class and is saved to the package directory.
- In the Extends box, enter the name of the class which this class extends.
- To generate header comments, such as Title, Version, Author, etc., click Generate Header Comments.
- To make the class public, click Public.
- To generate a default constructor, click Generate Default Constructor.
- To generate a main function, click Generate Main Function.
- Click OK to create the class.
The class is displayed as a .java source file in the Navigation pane.
See also:
Requirements for a class to be visually designable
Context-sensitive help: New Java File wizard
Creating an HTML file
An applet runs in an HTML file. The applet receives its display size and other run parameters from the HTML file. To embed an applet in an HTML file, you use the APPLET tag.
To create an HTML file,
- Choose File|New, then HTML.
If you do not have an active project, the Project wizard is loaded first, prompting you to create a project.
- An HTML file is created. It contains the HTML, TITLE, and BODY tags. The file is given the name untitledX.html, where X is a sequential number. The file is displayed as a source file in the Navigation pane. It contains minimal HTML tags.
See also:
Running applets
Using an HTML file to store arguments
Overriding methods
You override a method in a superclass with the Override Methods wizard. For example, if you want your subclass of a Frame, such as Frame1, to do something different from a regular Frame when another part of your program calls Frame1.getTitle(), you would use the Override Methods wizard to create the following code:
public java.lang.String getTitle() {
//TODO: override this java.awt.Frame method;
return super.getTitle();
}
When you're ready to use this code, replace the commented line with code that does what you want.
To override a method,
- Choose Wizards|Override Methods.
The Override Methods wizard is displayed.
- In the Class list, choose the name of the class you want to examine.
- Then, choose the name of the method(s) you want to override. The Methods list displays all methods in all inherited classes.
- Click OK to create the code to override the method(s).
- Display the class in the Editor and replace the commented line with code that you want.
See also:
Context-sensitive help: Override Methods wizard
Implementing a Java interface
Interface methods are a group of method declarations which provide basic functionality to classes that share common behavior or needs. This allows Java classes to span multiple class hierarchies even though a Java class can only inherit implementation from a single superclass.
A class that implements an interface must provide an implementation for all the abstract methods of the interface.
You can use the Implement Interface wizard to create an interface framework. Then, you need to write code that implements each method of the interface. The framework is inserted at the end of the .java source file for the class.
To implement an interface,
- Choose Wizards|Implement Interface.
The Implement Interface wizard is displayed.
- In the Class list, choose the name of the class you want.
- Then, in the Available Interfaces list, choose the name of the interface you want to implement.
- Click OK.
- Display the class in the Editor and replace the commented lines with code that you want.
See also:
Context-sensitive help: Implement Interface wizard
Bundling resources
A resource bundle is a file that contains some or all of the resource strings used in your application or applet. If you have coded your resources with strings, you can quickly bundle them into a separate resource bundle.
To bundle resources,
- Choose the class which contains resource strings you want to bundle.
- Choose Wizards|Resource Strings.
The Resource wizard is displayed.
- Enter the name of the class in which to bundle the resource strings.
- For each resource string displayed, click the Convert button to add the string to the resource bundle file and convert it to a call that retrieves the string from the bundle class.
Click Skip if you don't want to convert the string.
- When the wizard is finished, it automatically closes.
The resource strings are now bundled in the selected class or resource file. Each string is assigned an identifier. In the class selected when the wizard was run, identifiers have been substituted for the resource strings.
See also:
Context-sensitive help: Resource wizard
Specifying an action for a component
You use the Interaction wizard to specify an action for a component to perform when an event occurs. The Interaction wizard adds a listener for the component that generates the event. It also adds a method to your source code for performing the action.
To specify an action for a component to perform when an event occurs,
- Choose Wizards|Interaction Wizard.
The Interaction wizard is displayed.
- Choose the class that generates the event (the source component). Click Next.
- If the component you want to specify an action for does not appear in the Select a Component list, you can add it by clicking Edit Interactions. See Customizing the Interaction wizard for more information.
- If the component is already in the list, choose the one you want to use when the event occurs. Click Next.
- In the On Event list, choose the event the method responds to and click Next.
- Choose the action you want the method to perform in the Do the Following list. If the action needs to be specified, click Next. Otherwise click Finish.
JBuilder creates a method in your source code that performs the action when the event is generated.
See also:
Working with events in the Component Writer's Guide
Context-sensitive help: Interaction wizard
Customizing the Interaction wizard
The Interaction wizard, the wizard you use to specify an action for a component to perform when a selected event occurs, is aware of many JBCL and AWT components. You can customize this wizard to make it aware of other components, such as those found in a third party library.
To customize the Interaction wizard,
- Choose Tools|Interaction Wizard Editor.
The first page of the Interaction Wizard Editor is displayed.
- Enter the class name of the component you want to surface in the Interaction wizard. Click Next.
- Choose the commonly used events you want to expose by selecting the group name and then checking the This Event Group Exposed to Interactions check box. When you have chosen all the event groups that you want, click Next.
- Choose the commonly used methods you want to expose by selecting each method and checking the This Method Exposed to Interactions check box. When you have chosen all the methods that you want, click Finish.
The next time you run the Interaction wizard, the selected components, events, and methods will be displayed in the appropriate lists. You need to run the Interaction Wizard Editor for each class you want to surface in the Interaction wizard.
See also:
Context-sensitive help: Interaction Wizard Editor
Wrapping an applet
You wrap an applet to turn it into a JavaBean component. The component can then be placed on the Component Palette. The parameters that the applet understands are converted into properties.
To wrap an applet,
- Choose Wizards|Wrap Applet.
The Create Applet Wrapper wizard is displayed.
- Enter the name you wish to give the package and wrapper.
- Enter the HTML page or applet class file that needs to be wrapped. Click Next.
- If you select an HTML page and that page contains more than one class, choose the name of the class to wrap. Click Next.
- If the selected applet contains parameters, set the value of the parameters. Click Finish.
See also:
Context-sensitive help: Create Applet Wrapper wizard