Download Simple manual for using JBuilder.

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Scala (programming language) wikipedia , lookup

Structured programming wikipedia , lookup

Name mangling wikipedia , lookup

Library (computing) wikipedia , lookup

Go (programming language) wikipedia , lookup

C Sharp syntax wikipedia , lookup

Aqua (user interface) wikipedia , lookup

Computer file wikipedia , lookup

One-pass compiler wikipedia , lookup

Java (programming language) wikipedia , lookup

Java performance wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

Transcript
CS210 Computer Programming Fundamentals
Summer I 1999
CS210 Computer Programming Fundamentals
Getting Started with Java Using JBuilder
Introduction
JBuilder is an Integrated Development Environment (IDE) for developing Java programs. All the tools
(such as editor, compiler, project builder, debugger, and helper) are integrated into a single graphical user
interface instead of operating as separate programs (such as with Sun's JDK commands). With this manual,
you will learn creating a new project, editing, compiling and running Java programs.
1. Launch JBuilder.
From Windows Start button, choose Programs, Borland JBuilder, JBuilder to launch JBuilder. The
JBuilder user interface appears, as shown in Figure 1.1.
The user interface primarily consists of the main window and the AppBorwser window. The main
window is at the top of the screen when you start JBuilder. The main window serves as the
development control center, consisting of the menu bar, the tool bar and the Component Palette. The
AppBrowser window below the main window serves as information browser to create and view the
project, files, packages, user interface and code.
Figure 1.1: The JBuilder user interface consists of the main window and the AppBrowser window.
The main window consists of the menu bar, the tool bar and the Component palette. The menu bar
provides most of the commands you need to use JBuilder, for example, creating programs, editing
programs, compiling, debugging and running programs.
The tool bar provides buttons for several frequently used commands on the menu bar. Clicking a
toolbar is a faster way of choosing a command than using the menu bar. For some commands, you
may also use function keys. For example, there are three ways to save a file: (1) using the menu bar
File | Save, (2) using the tool bar button "save" and (3) using function key Ctrl+S.
The Component Palette contains visual components for Rapid Application Development. The
components are grouped into eight tabs: Controls, Containers, AWT, Dialogs, Data Access, Sun
Applets, KL Groups and Others. You may select a group of components by clicking on a tab. JBuilder
has the intelligent drag and drop capability that allows you to select a component such as a button and
drop on the user interface. In an advanced Java programming course, you will use component palette
for RAD. You will not use this feature in CS210. For this reason, the Component Palette is not
included in JBuilder University Edition.
CS210 Computer Programming Fundamentals
2.
Summer I 1999
Create a Project.
A project is like a holder to tie all the files together. The information about each JBuilder project is
stored in a project file with a .jpr file extension. This project file contains a list of all the files and
project settings and properties. JBuilder uses this information to load and save all the files in the
project and compile and run the programs.
Here are the steps to create a new project.
1.
2.
3.
4.
Choose File, New Project to bring up the Project wizard dialog box, as shown in Figure 1.2.
Replace "untitled1" by "Lab1" in the File field.
Fill in the title, author, company and description fields. These optional fields provide a description
for the project.
Click Finish. The new project is displayed in a new AppBrowser as shown in Figure 1.3.
Figure 1.2: The Project Wizard Dialog Window lets you specify the project file with other optional
information.
NOTE: For demonstration in this the manual, the files are stored in D:\CS160. If floppy
diskettes are used for storing files, replace D:\CS160 with A:\CS160.
Figure 1.3: Each project has an independent AppBrowser window.
3.
Create a New Java Source File.
CS210 Computer Programming Fundamentals
Follow the steps below to create a new Java source file for Welcome.java.
1.
2.
3.
Choose File, New to bring up the New dialog box, as shown in Figure 1.4.
Click the Class icon to bring up the New Object dialog box, as shown in Figure 1.5.
Type Welcome in the Class Name field and check Public in the Style section.
4. Click OK to generate the source as shown in Figure 1.6.
Figure 1.4: You can create a new Java class by clicking the Class icon in New dialog box.
Figure 1.5: The Object dialog box lets you create a class.
Summer I 1999
CS210 Computer Programming Fundamentals
Summer I 1999
Figure 1.6: Welcome.java was created from the New Class Wizard.
4.
Edit Source Code.
Type the code as shown in Figure 1.7. To save the change, choose File, Save or press CTRL+S.
Figure 1.7: Type Welcome.java to match Example 1.1 on page 10.
5.
Compile Source Code.
There are three ways to compile programs.
1.
2.
3.
(From main menu) Choose Build, Make "Welcome.java".
(Using short-cut button) Click the short-cut button for make, as shown in Figure 1.8.
(Using popup menu) Hightlight Welcome.java in the Navigation pane, and right click the mouse
to reveal a popup menu, as shown in Figure 1.9. Choose Make from the menu to compile it.
Figure 1.8: You can compile the source code using the short-cut button.
CS210 Computer Programming Fundamentals
Summer I 1999
Figure 1.9: You can compile the source code using the short-cut button.
6.
Fix Compilation Errors.
Suppose you mistype String with string and missed the semicolon in the Welcome.java file. When
compiling this program, a list of errors will be shown in the Compilation Output pane, as shown in
Figure 1.10.
Figure 1.10: Compilation errors are reported in the Compilation output pane.
Click an error in the list, the line that caused the error is highlighted in the Content pane. Fix the error
and recompile the program. Repeat the process until all the errors are fixed.
7.
Run Applications.
You can run the program from JBuilder. However, due to some limitations on Windows NT/95, the
DOS window closes after the program terminates. To see the output, you need to run the program from
the DOS prompt using the java command.
CS210 Computer Programming Fundamentals
Summer I 1999
From Windows Start button, choose Program, DOS-Prompt to open a DOS window and change to the
directory to D:\CS160\Lab1, where your project is stored, as shown in Figure 1.11.
Figure 1.11: You need to run non-GUI applications from a DOS console.
NOTE: You need to type
c:\jbuilder\bin\setvars c:\jbuilder
to set environment variables for running Java program in DOS prompt. You should put this line into
the autoexec.bat file, so you do not need to type for every DOS session.
NOTE: Alternatively, you can run the program from the D:\CS160 directory and use the following
command:
java Lab1.Welcome
8.
Develop an Applet.
We now turn our attention to creating, compiling, and running Java applets. The steps for creating,
editing, and compiling applets are the same as the ones for applications. However, the running
environment differs between applications and applets.
Follow the steps below to complete Example 1.2.
1.
2.
3.
4.
5.
6.
7.
Open project Lab1.jpr if it is not open.
Choose File, New to bring up the New dialog box, as shown in Figure 1.4.
Click the Applet icon in the New dialog box to bring up the Applet wizard, as shown in Figure
1.12.
In Step 1 of 3 of the Applet wizard, type WelcomeApplet in the Class field.
Click Finish to let JBuilder generate WelcomeApplet.java and WelcomeApplet.html.
JBuilder generated a lot of code in WelcomeApplet.java. You will learn the generated code in
Chapter 10, "Applets and Advanced Graphics." Edit WelcomeApplet.java to match Example 1.2
on page 15.
Choose WelcomeApplet.html in the Navigation pane and right click the mouse to reveal a popup
menu. Click Run to start the appletviewer utility to test the applet. The output is shown in Figure
1.13.
CS210 Computer Programming Fundamentals
Summer I 1999
Figure 1.12: Using the Applet wizard is a quick way to create an applet.
Figure 1.13: You can test applet from JBuilder using appletviewer.
NOTE: WelcomeApplet.html is automatically generated. No editing is needed. If you want to edit or
see the code in this file, select WelcomeApplet.html in the Navigation pane and choose the Source tab
in the Content pane. (See Figure 1.14)
Figure 1.14: You can edit WelcomeApplet.html in JBuidler.
9.
Modifying the Applet.
Let us modify WelcomeApplet.java to display "Welcome to CS160!" instead of "Welcome to Java!".
Here are the steps to modify the program.
1.
2.
Select WelcomeApplet.java in the Navigation pane and change "Welcome to Java" to "Welcome
to CS160".
Run WelcomeApplet.html.
CS210 Computer Programming Fundamentals
Summer I 1999
10. Changing the colors.
By default, the foreground color is black and background color is white. You may change these colors.
Add the following two lines before the drawString() method to change foreground to red and
background to yellow.
setForeground(Color.red);
setBackground(Color.yellow);
11. You may get a compilation error indicating that variable Color not found. To fix the problem, simply
add import java.awt.Color; below the import java.awt.Graphics; statement.
JBuilder IDE Options
It is crucial to understand JBuilder IDE options and to set options correctly. To set IDE options, choose
Tool, IDE Options to bring up the Environment Options, as shown in Figure 2.1.
Figure 2.1
The Environment Options dialog box let you set environment for JBuilder.
JBuilder places the .class files in the out path directory, in a directory tree that matches the arrangement of
the source directories. If the Out Path directory does not exist yet, it is automatically created.
The Class Path specifies the location for your .class files. The compiler needs to know where .class files
are, to check whether they are outdated and need to be recompiled. The compiler looks in the Compiler
Source Path for a source file, to determine whether each source file needs to be recompiled to bring the
.class files up to date.