CONTENTS Developing Professional Java™ Applets by K.C. Hopson Stephen E. Ingram C O N T E N T S Introduction Chapter 1 The Java Development Environment ● Tough Problems in Search of One Solution ❍ Why Java Is a Comprehensive Solution ❍ Why Object-Oriented Is Important ❍ Java as an Object-Oriented Language ❍ Java as a Portable Environment ❍ Java as High Performance file:///I|/1-57521-083-5/INDEX.HTM (1 of 21) [13/02/2003 12:27:39 }Ç CONTENTS ❍ Java in the World of Distributed Computing ❍ Java as a Secure Environment ● General Features of the Java Programming Language ❍ Data Types ❍ Literals ❍ Variables ❍ Comments ❍ Operators ❍ Keywords and Conditionals ❍ Loops ❍ Arrays ● Applets and Standalone Applications ❍ Creating an Applet ❍ Creating a Standalone Application ● Applets Versus Standalone Applications ● Summary Chapter 2 Object-Oriented Development in Java ● Introduction to Java Classes and Objects ❍ Basic Structure of a Class ❍ Creating an Object Instance ❍ Using Methods ❍ Overloading Methods ❍ Constructors ● Inheritance in Java ❍ Subclassing ❍ Method Overriding ❍ Calling Superclass Methods ❍ Calling Superclass Constructors ● Important Core Classes ❍ The Object Base Class ❍ String Classes ❍ Type Wrappers ● More about Classes ❍ Access Modifiers ❍ Class Methods and Class Variables ❍ The final Modifier file:///I|/1-57521-083-5/INDEX.HTM (2 of 21) [13/02/2003 12:27:39 }Ç CONTENTS ❍ The null Keyword and More about Garbage Collection ❍ Scoping Rules ❍ Casting Rules ❍ Other Keywords ● Introduction to Exception Handling ❍ Structure of an Exception Handler ❍ When to Catch Exceptions ❍ Exception Handlers and Exception Classes ❍ Nested Exceptions ● Organizing Projects in Java ❍ Abstract Methods ❍ Interfaces ❍ Packages ● The Java Developer's Kit ● Summary Chapter 3 Building a Spreadsheet Applet ● Overview of AWT: Part 1 ❍ AWT Classes ❍ Components and Containers ❍ Layouts ❍ Event Handling ● Exception Classes ❍ The Throwable Class ❍ Exception Class Hierarchy ❍ Exception Handlers and Throwable Classes ❍ Writing Custom Exception Handlers ❍ Class Organization ❍ The Cell Class ❍ The Cell Container Class ❍ The FormulaParserClass ❍ The FormulaParserException Class ❍ The ArgValue Class ❍ The SpreadsheetCell Class ❍ The SpreadsheetContainer Class ❍ The SpreadsheetFrame Class ❍ The SpreadsheetApplet class file:///I|/1-57521-083-5/INDEX.HTM (3 of 21) [13/02/2003 12:27:39 }Ç CONTENTS ● Summary Chapter 4 Enhancing the Spreadsheet Applet ● Overview of AWT: Part 2 ❍ Windows and Frames ❍ Menus ❍ Dialogs ❍ Colors ❍ Fonts ❍ The Toolkit Class ● I/O and Streams ❍ Structure of the java.io Package ● I/O and Security ❍ I/O Exceptions ❍ InputStream Classes ❍ OutputStream Classes ❍ FilterOutputStream Classes and FileOutputStream ❍ Other Output Classes ❍ Other I/O Classes ● Tutorial ❍ Class Organization ❍ Adding the Color Dialog ❍ Font Dialog Box ❍ The FileDialog Class ❍ Saving a Spreadsheet File ❍ Opening a Spreadsheet File ● Summary Chapter 5 Adding Graphs and Scrollbars to the Spreadsheet ● Tutorial ❍ Class Organization ● Adding Scrollbars ❍ Adding the Scrollbar Class ❍ Handling Scrollbar Events file:///I|/1-57521-083-5/INDEX.HTM (4 of 21) [13/02/2003 12:27:39 }Ç CONTENTS ❍ Inside the SpreadsheetContainer Paint Methods ● Marking Cells ● Drawing Graphs ● Summary Chapter 6 Building a Catalog Applet ● Basics of the Applet Class ● Applets and HTML ● Applets and Images ● Applets and Audio ● Under the Applet Hood ● Creating and Reading a URL ● Chapter Project ❍ Class Organization ❍ Catalog HTML ❍ The Catalog Class ❍ The CatalogButton Class ❍ The SelectionCanvas Class ❍ The MediaLoader Class ❍ The MediaLoaderException Class ● Summary Chapter 7 Java and Images ● Displaying Images ❍ Loading Java Images ❍ Image Display ❍ Image Observers ● Tracking Image Loading ● The Consumer/Producer Model ● Java Color Models ❍ Default RGB ❍ Direct Color ❍ Index Color ● Chapter Project: Displaying a Windows BMP Image ❍ Using Image Types Not Supported by Java file:///I|/1-57521-083-5/INDEX.HTM (5 of 21) [13/02/2003 12:27:39 }Ç CONTENTS ❍ Memory Images ❍ Loading Foreign Images ❍ BMP File Format ❍ Reading Unsigned Binary in Java ❍ Creating the Color Table ❍ Constructing the Image ● Summary Chapter 8 Adding Threads to Applets ● What Is a Thread? ● Creating a Thread with the Thread Class ❍ Enhancing Your First Multithreaded Applet ● The Runnable Interface ● Synchronization ❍ A TestStack Class That Is Not Thread-Safe ❍ Introducing the Synchronized Modifier ❍ Notify and Wait ● More About Threads ● ThreadGroups ❍ ThreadDeath ● Talking Threads: Pipes and Threads ● Chapter Project ❍ Class Organization ❍ Catalog HTML and Preload File ● The MediaLoaderThread and MediaObserver Classes ❍ The MediaLoader Class ❍ The MediaSweeper Class ❍ The Queue Class ❍ The BMPImage Class ❍ The Catalog Class ❍ The CatalogButton Class ❍ The SelectionCanvas Class ● Summary Chapter 9 Java Socket Programming file:///I|/1-57521-083-5/INDEX.HTM (6 of 21) [13/02/2003 12:27:39 }Ç CONTENTS ● An Introduction to Sockets ❍ Socket Transmission Modes ❍ Java Connection-Oriented Classes ❍ Iterative and Concurrent Servers ❍ Java Datagram Classes ❍ Applet Security and Sockets ● Chapter Project: HTTP Server Application and Client Applet ❍ Chapter Project: HTTP Server Application and Client Applet ❍ Basic Web Server ❍ Client Datagram Applet ❍ Client Applet ● Summary Chapter 10 Native Methods and Java ● Deciding to Use Native Methods ● Native Methods from the Java Side ● Writing Native Methods ❍ Using Javah ❍ Java Arrays ❍ The Stubs Code ● Chapter Project: A Database Interface Library Using ODBC ❍ Calling Back Into Java ❍ Constructing Java Objects from C ❍ Creating the Library ● Database Server ● Adding Packet Assembly to DGTP ❍ The Election Server ● Election Client ● Summary Chapter 11 Building a Live Data Applet ● Observers and the Model-View Paradigm ● Chapter Project ❍ General Architecture of the Project ❍ Changes to the Server file:///I|/1-57521-083-5/INDEX.HTM (7 of 21) [13/02/2003 12:27:39 }Ç CONTENTS ❍ Applet Client ● Summary Chapter 12 Handling Dynamic Content ● Introducing the HotJava Browser ❍ Dynamic Content ❍ Security Model ❍ Alpha3 Distribution Differences ● Altering the HotJava Source ❍ Buffered Streams Primer ❍ Making the Changes ❍ Compiling Under HotJava ● Toward a More Perfect Server ❍ Adding a Configuration File ❍ Adding Standard Logging ❍ Building Log Information ❍ Altering the Send Routines ● Creating New Content Types ❍ Writing Content Handlers ● Summary Chapter 13 Animation and Image Filters ● Simple Animation Using Images ● Image Producers ❍ Image Consumers ● Filtering an Image ❍ FilteredImageSource ❍ Writing a Filter ❍ Static Image Filter: Rotation ❍ Double Buffering ❍ Dynamic Image Filter: FXFilter ● Corporate Presentation Applet ❍ How the PresentImage Applet Works ● Summary file:///I|/1-57521-083-5/INDEX.HTM (8 of 21) [13/02/2003 12:27:39 }Ç CONTENTS Chapter 14 Advanced Image Processing ● Chapter Project ● Class Organization ● How It Works ● Fractals and the Mandelbrot Set ● Using the Applets ● The Mandelbrot Class ● CalculateFilterNotify Interface ● CalculatorProducer Interface ● The CalculatorFilter Class ● The CalculatorImage Class ● The MandelApp Class ● The MandelZoomApp Class ● The BmpImage Class ❍ Automatic Documentation with javadoc ● Summary Appendix A Inside the Java Virtual Machine ● The Class File ❍ Layout ● The Virtual Machine ❍ Registers ❍ Operand Stack ● Primitive Types ● Local Variables ❍ The Verifier ❍ Exception Handling ❍ Bytecodes ❍ Test Class Bytecodes ● Garbage Collection Appendix B Language Grammar file:///I|/1-57521-083-5/INDEX.HTM (9 of 21) [13/02/2003 12:27:39 }Ç CONTENTS Credits To my wife, Ann, whose love, patience, assistance, and encouragement made it possible for me to write this book K.C. Hopson To my wife, Anne, and my son, Mitchell; their love and encouragement gave me the strength to write this book Stephen Ingram Copyright © 1996 by Sams.net Publishing FIRST EDITION All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Neither is any liability assumed for damages resulting from the use of the information contained herein. For information, address Sams.net Publishing, 201 W. 103rd St., Indianapolis, IN 46290. file:///I|/1-57521-083-5/INDEX.HTM (10 of 21) [13/02/2003 12:27:39 }Ç [...]... tool for sprucing up your Web pages is a serious understatement of its capabilities Java applets will appear in more guises than just the Internet, and Java' s role inside internal networks-the so-called "Intranet"-is already being given serious consideration Developing Professional Java Applets aims to help bring Java applets out of the world of lightweight programs-like simple animations-into the world... build highquality, professional Java applets Thoughts Before Starting There are a variety of Web sites cropping up that help you with various aspects of Java The main launching pad for Java is http://www.javasoft.com/, which is where you can download the latest Java release and all kinds of first-rate documentation The newsgroup comp.lang .java has excellent discussions of all aspects of Java programming,... doing so, you will not only become a more capable Java programmer, but you might also develop insights on how to use Java to create a great new application Who Should Read This Book Developing Professional Java Applets is intended for people who do not want to spend 200 pages learning basic Java (such as for loops), but want to quickly step into serious Java programming To do this, however, requires you... 12:27:39 }Ç Chapter 1 The Java Development Environment Chapter 1 The Java Development Environment CONTENTS q q q q q Tough Problems in Search of One Solution r Why Java Is a Comprehensive Solution r Why Object-Oriented Is Important r Java as an Object-Oriented Language r Java as a Portable Environment r Java as High Performance r Java in the World of Distributed Computing r Java as a Secure Environment... of the Java Programming Language r Data Types r Literals r Variables r Comments r Operators r Keywords and Conditionals r Loops r Arrays Applets and Standalone Applications r Creating an Applet r Creating a Standalone Application Applets Versus Standalone Applications Summary Java is a programming language that provides a foundation for developing Internet applications Java does this through applets, ... currently existing Java literature: a book full of serious, practical, and professional Java projects and examples The projects in this book illustrate how to create Java applets that solve real-life problems, and they do so in such a way that you will learn all file:///I|/1-57521-083-5/INDEX.HTM (15 of 21) [13/02/2003 12:27:39 }Ç CONTENTS the general features, as well as subtleties, of Java while you're... How This Book Is Organized This book is based on the Java Development Kit (JDK), version 1.0 Most of the chapters of Developing Professional Java Applets have a tutorial section that covers some JDK topics, followed by a serious chapter project The chapter project is accompanied by a discussion of the project's general architecture, as well as any Java subtleties it might uncover By the time you are... images By the end of this part, you will have been through some of Java' s most complex features Part IV takes you into the world of Java client/server programming It introduces you to Java network programming through the creation of an HTTP server This server will actually download Java applets to a client! You will also be shown how to use Java native methods-code written in Cby tying in databases (through... 12:27:39 }Ç CONTENTS Java applets, however, are much more than small programs that supplement Web pages Java is a sophisticated and extendable environment, providing the foundation for building industrialstrength applications This power stems from Java' s many facets-from its object-oriented nature to its simplicity to its ability to function in distributed environments Consequently, to view Java as a "neat"... to at least one serious Java programming concept Part I of the book is a quick overview of the fundamentals of Java programming If you have no experience with Java, this part should be enough to get you ready for the heart of the book It includes plenty of examples to illustrate key ideas However, the book's focus is on practical Java programming, so some of the discussions of Java basics are file:///I|/1-57521-083-5/INDEX.HTM . "Intranet"-is already being given serious consideration. Developing Professional Java Applets aims to help bring Java applets out of the world of lightweight programs-like simple animations-into. to use Java to create a great new application. Who Should Read This Book Developing Professional Java Applets is intended for people who do not want to spend 200 pages learning basic Java (such. currently existing Java literature: a book full of serious, practical, and professional Java projects and examples. The projects in this book illustrate how to create Java applets that solve