Table of Contents
acknowledgments xix
introduction xxi
Who should read this book? xxii
So what is Java all about? xxii
Enter Java xxiii
More than pretty graphics xxiii
Why learn Java? xxiii
Why learn PowerJ? xxiv
Why use PowerJ to develop your business applications? xxiv
Source code xxv
Author online xxv
Finally, a note about using the mouse xxv
Part I
The basics 1
1 Java basics 3
1.1 Java's portability 5
1.2 Java is more than Web-based multimedia and business content 5
1.3 Java is object oriented 6
1.4 Learning Java 6
1.5 Java classes 7
Relationship between classes and objects 7
1.6 What is an object? 7
Objects versus classes 10
Instances of classes 10
1.7 What is inheritance? 11
The benefits of inheritance 13
1.8 Classes and objects provide encapsulation and polymorphism 13
1.9 Object-based programming versus object-oriented programming 14
1.10 The AWT classes 15
1.11 Event-driven systems 15
1.12 Do I need to know object-oriented programming? 15
1.13 Elements of the Java language 16
Java variable types 16
Scope of variables 17
Access modifiers 18
Variable names 18
Operators 18
Flow-control statements 19
1.14 Initializing objects from class definitions 22
1.15 Enhancements to Java 1.1 23
1.16 Summary 24
2 PowerJ basics 25
2.1 Starting PowerJ 26
The main PowerJ window 27
The main menu 28
Toolbar 28
Java component palettes 29
Status bar 31
Form design window 31
Object inspector 32
Object list window 33
Targets list window 34
Files list window 36
Classes list window 37
2.2 The code editor 38
2.3 The on-line help system 38
2.4 The reference card 39
2.5 Summary 40
3 Your first programs 41
3.1 Types of applications 42
Java applets 42
Java applications 42
Web applications 42
Java web server application 42
Dynamo server applications 42
3.2 Steps to creating a program 43
Designing the user interface 44
The to-do list window 45
Adding the list control 45
Adding the text box 46
Adding the buttons 46
Testing what you have done so far 47
Setting the tab order 48
Specifying object properties 49
Labeling the buttons 49
Adding code 50
Adding to the list control 54
The delete button code 55
Sprucing up the user interface 56
Still not complete 56
Testing the application 56
3.3 Building the application 57
3.4 Saving your project 57
3.5 Enhancements to the project 59
3.6 Creating an applet 59
3.7 Summary 64
Part II
Putting PowerJ to work 65
4 Working in PowerJ 67
4.1 Using the form design window 68
4.2 The form grid 69
Grid Size 70
Aligning objects to the grid 70
4.3 Resizing the form window 71
4.4 Creating a new form 71
4.5 Types of forms 71
4.6 Adding new forms to the project 72
4.7 Opening and closing forms 73
To close a form design window 74
To open a closed form design window 74
4.8 Changing a form's properties 74
Setting a form's properties 74
4.9 Making your forms work 76
4.10 Adding objects to a form 77
4.11 The component palette 77
4.12 Adding components to forms 78
4.13 Positioning an object on the form 78
4.14 Changing the position of an object on a form 78
4.15 Changing the size of an object 79
4.16 Deleting an object from a form 79
4.17 Deleting an entire form 80
4.18 Copying an object 81
4.19 Cut operations 82
4.20 Copy, cut, and paste shortcuts 82
4.21 Aligning objects 82
4.22 Matching object sizes 83
4.23 Working with object properties 83
4.24 Changing an object's properties 83
Accessing the properties dialog 84
4.25 Changing an object's name 86
4.26 Adding and modifying event handlers 87
4.27 Creating event handlers 87
4.28 Summary 89
5 Using the PowerJ standard objects 90
5.1 The standard components 91
5.2 Two Javas are better than one 92
5.3 Many objects have common properties 92
The label property 93
The visible property 94
The enabled property 94
Color property 95
The object name property 97
Additional common properties 98
5.4 Run-time-only properties 98
5.5 Component review 99
The selection tool 99
The button (java.awt.button) 99
The check box (java.awt.Checkbox) 101
The choice control (java.awt.Choice) 103
The label control (java.awt.Label) 106
The list (java.awt.List) 106
The menu bar (java.awt.MenuBar) 109
The panel (java.awt.Panel) 110
The scroll bar (java.awt.Scrollbar) 110
Text box 112
The group box (powersoft.powerj.GroupBox) 115
The masked text field (powersoft.powerj.ui.MaskedTextField) 115
The multiline label (powersoft.powerj.ui.MultiLineLabel) 118
The paint canvas (powersoft.powerj.ui.PaintCanvass) 118
The picture box (java.awt.PictureBox) 118
The picture button (powersoft.powerj.ui.PictureButton) 120
The tab control (powersoft.powerj.ui.TabControl) 120
The grid control (powersoft.powerj.ui.Grid) 122
5.6 Summary 127
6 Using menu objects 128
6.1 Adding a menu object to a form 129
6.2 Menu name property 129
6.3 The default menu 130
6.4 Adding menu items to the menu bar 131
6.5 The menu editor dialog 132
6.6 Adding child items 133
6.7 Setting menu properties 134
6.8 Accelerator key 135
6.9 Menu separators 135
6.10 When to use menu items 135
6.11 Deleting menu items 136
6.12 Writing menu code 136
6.13 Enabling and disabling menu items 137
6.14 Checking menu items 137
6.15 Making the menu item visible or not visible 137
6.16 Changing the text of menu items 137
6.17 Removing menu items 138
6.18 Adding items to menu 138
6.19 Summary 139
7 The standard datatype classes 140
7.1 The object class (java.lang.Object) 141
7.2 The string class (java.lang.String) 142
7.3 The StringBuffer class (java.lang.StringBuffer) 143
7.4 The integer class (java.lang.Integer) 144
7.5 The point class (java.awt.Point) 144
7.6 The dimension class (java.awt.Dimension) 144
7.7 The rectangle class (java.awt.Rectangle) 144
7.8 Miscellaneous classes 145
7.9 Summary 145
8 The code editor & drag-and-drop programming 146
8.1 The PowerJ code editor 147
8.2 Opening the code editor 147
8.3 Color your world 149
8.4 Coding in color 149
8.5 Saving source code 150
8.6 Undo and redo 151
8.7 Two editors in one 151
8.8 Drag-and-drop programming 152
The reference card 153
Methods that return values 156
The object prefix 157
Reference card organization 157
8.9 Summary 157
9 Working with forms and windows 158
9.1 Creating new forms 159
9.2 Types of forms 159
9.3 Navigating through forms at design time 159
9.4 Setting the main form 161
9.5 Form code 161
9.6 Adding new functions and events to the form 162
Adding a user function 162
Adding a new property to a form 163
Adding new methods 165
Adding events to forms 167
9.7 Opening forms at run time 170
9.8 Destroying a form 170
9.9 The WindowDestroy event 170
9.10 Putting some of this to work 171
9.11 Opening another window 173
9.12 Summary 174
10 Working with targets and projects 175
10.1 What are targets? 176
10.2 What are projects? 176
10.3 Starting new projects after PowerJ has started 177
10.4 Opening an existing project 177
10.5 Closing projects 178
10.6 Running your project's targets 178
10.7 Run options 179
10.8 Debugging your program 181
10.9 Target versions 181
10.10 Project backups 182
10.11 Working with projects 182
Adding new targets to your project 183
Adding source files to targets 185
Adding classes 186
Deleting targets and files 188
Building targets 189
10.12 Debug versus release versions 191
Separate build options for debug and release versions 192
10.13 Source control systems 192
10.14 Summary 194
11 Debugging applications 195
11.1 The art of debugging 196
11.2 Setting breakpoints 196
11.3 Rules for setting breakpoints 197
11.4 Advanced breakpoint options 197
11.5 Running in the debugger 199
11.6 Debug mode 200
11.7 Stepping through the code 201
11.8 Examining values in variables 202
11.9 Other debugger windows 204
The locals window 204
Call stack 207
The assembly window 208
The registers window 209
The threads window 211
The memory window 211
The stack window 212
11.10 Breaking without breakpoints 213
11.11 Summary 213
Part III
Extending PowerJ--classes, templates, databases & more 215
12 Defining and using templates 217
12.1 The advantage of templates 218
12.2 Creating templates 218
12.3 Creating templates from entire forms and targets 220
12.4 Using a template on a form 220
12.5 Deleting templates 220
12.6 Storage of templates 220
12.7 Templates do not use inheritance 221
12.8 Summary 222
13 Using classes in PowerJ 223
13.1 Types of classes 224
13.2 Adding classes 225
13.3 Creating a contacts class 227
13.4 Summary 232
14 Using databases 233
14.1 Security issues for databases 234
14.2 Methods of connecting to databases 235
What is JDBC? 235
What is the JDBC-ODBC bridge? 236
What is Sybase jConnect for JDBC? 237
14.3 Using databases in PowerJ 237
Transactions 237
JDBC driver 238
DataSource URL 238
UserID 239
Password 239
ConnectParams 239
AutoConnect 239
AutoCommit 239
TraceToLog 240
14.4 Setting transaction properties at run time 240
14.5 Making the connection 240
14.6 Disconnecting from the database 241
14.7 Transaction management 241
14.8 Query objects 242
14.9 Relationships with transactions 243
14.10 Query properties 243
Transaction (located on the query tab) 244
SQL 244
The query editor 245
Parameters for queries 253
Stored procedures 254
Additional query properties 254
Setting query properties at run time 255
Run-time-only properties 255
14.11 Executing the query 256
Result sets 256
Row numbers 256
Retrieving the result set 256
Getting the current row 256
Moving through the result set 257
14.12 Closing the query 258
14.13 Direct SQL 258
14.14 Bound controls 259
Setting the DataSource and column 260
The DataSource property 261
The DataColumns property 261
Getting specific values 261
When to use bound list boxes 262
14.15 Making changes to the database 262
Making deletes 263
Adding rows 263
Modifying existing data 264
14.16 Refreshing the result set 264
14.17 Canceling updates 265
14.18 The data navigator 265
Vertical versus horizontal 265
Choosing the buttons 265
14.19 Using database forms 266
14.20 Building a contacts database 270
14.21 Summary 275
15 Building applications for the Internet 276
15.1 Internet concepts 277
15.2 Internet programming components 278
Sockets 278
Internet objects 285
HTTP object 286
FTP objects 288
15.3 Web applications 291
15.4 Web projects 291
15.5 Building the web application 291
15.6 Publishing the web application 291
15.7 Creating a web target 291
15.8 Running the web target 292
15.9 Web services 292
Common Gateway Interface 292
Proprietary web services 292
15.10 Let's build a sample application 293
15.11 Summary 299
16 Using JavaBeans and ActiveX 300
16.1 JavaBeans 301
16.2 JavaBeans versus ActiveX 301
16.3 Using JavaBeans in PowerJ 301
16.4 Placing JavaBeans on the palette 302
16.5 Creating JavaBeans in PowerJ 304
16.6 Setting properties 305
16.7 Using ActiveX controls in PowerJ 305
16.8 Server-side versus client-side 306
16.9 Adding a control to the component palette 306
16.10 Registering ActiveX controls 307
16.11 Programming by proxy 308
16.12 Using the control from the applet form 309
16.13 Using the reference card 310
16.14 Summary 311
17 Creating and using graphics 312
17.1 Creating a graphic context 313
17.2 Graphics properties 313
ClipRect 314
Color 314
Font 314
17.3 Watch your memory 314
17.4 Drawing in a graphics object 314
Drawing lines 315
Drawing rectangles 315
Filling the rectangle 315
Clearing a rectangle 315
Drawing ovals 316
Drawing arcs 317
Drawing filled arcs 317
Drawing polygons 317
Filling polygons 318
17.5 Text 318
17.6 The image class 318
Placing an image in a graphics context 319
17.7 Creating an application 319
17.8 Summary 324
18 Build options and running the application 325
18.1 Build options 326
18.2 The class path tab 327
18.3 Debug versus release targets 328
Build options for debug and release versions 328
18.4 Restoring defaults 328
18.5 Deploying your Java applet to a Web server 329
Step 1. Create a release version of your project 329
Step 2. Add a Web application target 329
Step 3. Editing the HTML 330
Step 4. Set the location to publish your Web Application 330
Step 5. Build the Web application 331
18.6 Using the newest Java 332
18.7 Summary 333
19 Where do we go from here? 334
19.1 Java on the web 335
19.2 Java publications 335
19.3 Other Java books 335
19.4 Practice makes perfect 335
19.5 Summary 336
appendix 337
index 341