Table of Contents

acknowledgments xix

introduction xxi

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

1.6 What is an object? 7 1.7 What is inheritance? 11 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

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 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 3.2 Steps to creating a program 43 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

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

4.8 Changing 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

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

5.4 Run-time-only properties 98 5.5 Component review 99 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

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

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

10.12 Debug versus release versions 191 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 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

14.3 Using databases in PowerJ 237 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

14.11 Executing the query 256 14.12 Closing the query 258

14.13 Direct SQL 258

14.14 Bound controls 259

14.15 Making changes to the database 262 14.16 Refreshing the result set 264

14.17 Canceling updates 265

14.18 The data navigator 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

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

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

17.3 Watch your memory 314

17.4 Drawing in a graphics object 314

17.5 Text 318

17.6 The image class 318

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

18.4 Restoring defaults 328

18.5 Deploying your Java applet to a Web server 329

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