This chapter describes scenarios for developing the following kinds of applications:
Distributed or Web applications using EJB Server in the middle tier
Client/server applications
Applets, applications, components, and Web server extensions There are several types of Java programs: applets, applications, components, and Web server extensions. PowerJ generates behind-the-scenes code for each of these types so that you don’t have to write as much code for the mechanics of the program. You can concentrate on program-specific code.
Applets An applet is a Java program that requires a host program, such as a browser, to run. An applet is usually part of an HTML page and is downloaded when it is needed. You don’t have to deploy applets to individual computers. Because they are downloaded as needed, applets should be small so users don’t get impatient waiting for the applet to start.
Because applets are downloaded, they are subject to restrictions so they can’t harm the user’s system. For example, applets cannot access the local file system and can make connections only back to the server they came from.
Your applet class will extend the standard class java.applet.Applet, which provides default implementations for the init, start, stop, and paint methods. In your applet source file, PowerJ generates code to override the init method.
Applications A Java application behaves like any other program. In Java terminology, an application is a Java program that does not require a host server or browser to run. The user sees windows and menus and interacts with controls. The application can connect with a middle-tier or database server.
Since applications must be locally installed rather than downloaded each time they are run, they can be larger than applets. The user’s class path environment variable must include the directories containing the application’s code files.
A standalone application has a main method that runs when the application starts. It includes a main form and can include other forms, including dialog boxes and frames with menus.
Components Components are standardized, reusable pieces of software that are hosted in another program. You can install them in servers that are designed to host components like EJB Server, or include them in Java applications.
Business-logic components consist of methods that implement business rules and other application logic. These components can be included in a client application, but are more typically hosted in a component server like EJB Server in a distributed application.
User-interface components are used in client applications to enhance the user interface. Typically, user-interface components extend standard user interface classes. For example, a custom list box component might provide custom sorting methods, or a text box or check box might have data awareness.
In PowerJ, you can add components to the component palette and include them in your applications. You can put components on your forms, customize them, and use their methods through the Reference Card and drag-and-drop programming. For business-logic components on an EJB Server, when you add a component to PowerJ, a proxy for it is added to the palette. You can then use distributed components just as you would local components.
In PowerJ, it is easy to create JavaBeans components. A Bean might be an encapsulated user-interface component, such as an enhanced button with custom functionality, or it might be a business-logic component that includes methods and events. You can use the class, method, property, and event wizards to create the Java classes for the component. You can also write code that allows the JavaBeans user to modify properties at design time. There are specific standards and conventions for creating Beans.
Web server extensions You can create Web server extensions that follow the Java Servlet API. You can deploy servlets in EJB Server or other Web servers that support Java Servlets. For Web servers that do not directly support the Servlet API, PowerJ provides a DLL that translates from CGI, NSAPI, or ISAPI to the Servlet API.
You use PowerJ to build most of the pieces of the applications described here. Some of the activities for building a Java application are listed below. Depending on which application architecture you choose, some of these activities may apply to creating the client and others to creating the server.
Create a workspace, then create a target, which is the type of program you want to build. A workspace can include several targets, where each target is a part of a larger application.
Create the user interface by creating one or more forms and adding controls and nonvisual components.
Optionally, add menus by creating a frame (a type of form), adding a MenuBar object to the frame, and using the Menu editor to design menus.
Optionally, access database data by adding transaction and query objects to the form. Make the visual components of the form bound to the query object.
Code application-processing logic. You can place this code in different locations:
In events and methods for a form, control, or menu
In events and methods for nonvisual components on a form (PowerJ calls these framework classes—they are visible at design time as icons)
In classes that you add to your application
The PowerJ Reference Card and drag-and-drop programming make it easy to look up classes, properties, and methods and insert appropriate code in your program.