Currently, we have 4 java beans in this project by sir17308

VIEWS: 18 PAGES: 33

									Currently, we have 4 java beans in this project. They are Database
connection bean, Database table bean, Draw chart bean,

and Copy file bean . All these beans were developed in JBuilder7 enterprise
edition by using JDK1.4.

For using these beans you can follow the steps below.

1.To add components from current project in JBuilder, you have to create a
library for the current project, then select this library from the Palette
Properties .

2 To create a library, choose Tools, Configure Libraries to bring up a
Library properties box. Click new to display the New Library wizard, as
shown in Figure 1.1


Figure 1.1
. Enter the new Library name – Oracle in the Name field and add the path for
classes12_g.zip( which can be downloaded at
  http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html or some
other websites) in the Class section,
  as shown in Figure 1.2.




Click OK to add the library. Then, you can go ahead to add another four
Libraries (connecttionpanel, DatabaseTables, drawchart and copyfile).
The installations for these two libraries are a little different from Oracle
library, because these two are Jbuilder projects instead of JAR files. To
do this, you have to specify the path of src and classes folder of
ConnectionPanel DataBaseTable, DrawChart and CopyFile. as shown
in Figure 1.3.




Figure 1.3




Figure1.3.1
Figure1.3.2
Figure1.3.3
Figure1.3.4
Figure1.3.5
3.1 All the classes from AWT and Swing are already beans. Some of them,
such as JList, JButton ans JTable, are already added into the Swing page and
Swing Containers group in the component palette.
3.2 Suppose we want to use all the four beans, which we mentioned before,
in the JBuilder visual environment. First we must add it to the component
palette following the steps below.

1) Choose Tools, Configuration Palette or right-click anywhere in the
   component palette and choose Properties. The palette Properties dialog
   box appears, as shown in Figure1.4

Figure 1.4
Figure 1.5

2)Select the Pages tab and choose the page on the component palette on
which we want the component to appear. Optionally, we may create a new
page by clicking the Add button and entering the page name in the Add Page
dialog box.

3)Suppose we want to add new beans to the Other group. Select Other in the
pages column and click the Add components tab to display the dialog box
for adding components, as shown in Figure1.6
Figure1.6




4.Click the Selected Library button to display the Browser for Class dialog,
as shown in Figure 1.7.


Figure 1.7
5).Then, click Add From Selected Library button to locate
Connectionpanel ,CreateTable, DrawChart and CopyFile in the
connectionpanel, databasetable, drawchart and copyfiles package, as shown
in Figure 1.8


Figure1.8
6)Click OK in the Browser for Class dialog box to display a dialog box , as
shown below:
7.
  At this point of time, we are ready to test the beans you just added to the
component palette. First of all, you need create a new project. Choose File,
New Project to bring up the Project wizard dialog box, as shown in Figure
2.0


Figure2.0
Because this is Database application. We are going to use the JDBC driver
from Oracle library we just installed. Click next go to Project Wizard Step 2
of 3. Add Oracle9i into the Required libraries box as shown below:
Then click Finish button to finish creating a new Project.

8. Next step, we need create a new application. To do this, choose File, New
to display the Object Gallery. Click the Application icon to bring up the
Application wizard, as shown Figure 2.1 and 2.2
Figure2.1
Figure2.2

9.Type BeanTest in the Class field of the Application wizard Step 1 of 2 and
Next to display the Application wizard’s Step 2 of 2, as shown in Figure 2.3
Figure2.3

10. Check Center frame on screen. Click Finish.

11.The new project should looks like this in JBuilder.
11.With the Frame1.java selected in Project Pane, choose the Design tab in
the content pane to start the UI designer. Then, select contentPane in the
component tree. Select its layout property on the Properties tab of the
Inspector. Click the drop-down arrow and select null from the list as follow:
12.To use all the beans we just added in JBuilder, click the
Connectionpanel ,CreateTable, DrawChart and CopyFile components from
the Other tab in the component palette and drop them in the frame, as shown
in Figure 2.4
Figure2.4

13. select contentPane in the component tree. Select its connecttoTable
property on the Properties tab of the Inspector. Set the value to True. In the
meantime, also set the value of copyfile and drawchart to be true. as shown
in Figure 2.5


Figure2.5.1
Figure2.5.2
Figure2.5.3
14. After all these done, choose the Source tab in the content pane to go back
source code page of Frame1.java. Add three more lines code in Frame1.java

connectionpanel1.setTable(tableEditor1);
connectionpanel1.setChart(drawChart1);
connectionpanel1.setCopy(copyfiles1);
15. The next thing we need to do before we can run the program is set the
    properties of DrawChart bean.
    To do this, select drawChart1 in the component tree. In the component
    inspector for drawChart1,set the value of nameTo property to 1 and the
    value of numbers to 3.
    We do this because the following is what our testing database looks like:

   Name                                   Type
   ------------------------------- -------- -------------
   F_NAME                                CHAR(10)
   L_NAME                                 CHAR(10)
   AGE                                NUMBER(38)
   The value of nameTo property tells the program which column of
   database will be used as a name showing up at the drawChart
   bean . Here we set it as 1, which means the F_NAME will be there on
   the chart.

   Changing numbers to 3 let program it should draw charts depends on
   each person’s age




15. At this point of time , we are ready to test our program.
    After running, it should looks like this:
16 To connect a database(Oracle 8i running on zaurak.cis.ksu.edu), select
JDBC driver, and DataBase URL. Type your User Name , Password and the
name of the table where you wan t to get information from. Click Connect
button, all the items currently in the table will be list in the table. You can
insert , delete, or update all these information.




To insert a new record
To delete a record, select a record first, then delete it.
To change information of records:

								
To top