You can add your application logic in event handlers, methods, or external classes. In choosing where to add this code, keep in mind that effective encapsulation will make your classes more reliable and reusable. Don’t try to accomplish everything in a single method.
At design time, PowerJ makes it easy for you to write code that gets executed when events are triggered. PowerJ takes care of the infrastructure for events, such as event sources and listeners. You just write event-handler code that you want to be run when the event occurs.
If you want to set up a new event handler in your code, then your code must set up the event infrastructure.
When you add a new method, PowerJ inserts the method declaration and opens the code window so you can write the method’s code.
When writing code, you can use the PowerJ Reference Card to look up methods and properties of classes and components and then insert the method calls into your code.
In Java, a class provides the definition of an object; an object is an instantiation of a class. An application with a user interface includes forms, which are classes with specific support for the design environment. You can also have classes that are not forms. For these classes, you work in the Workspace view and code editor. You add methods to the class to contain the application logic.
You can add a class to a target and use the Workspace view to add properties, methods, and events to the class. This is called a managed class because PowerJ has records of the functions it contains.
You can also add a Java source file to a target. You can edit the source in the code editor, but the Workspace view does not display the methods and properties of the class. The extension for a source file is .java.
PowerJ uses an enhanced file format for saving forms and managed classes. Files for forms have the extension .wxf; files for managed classes have the extension .wxc. When you build your application, PowerJ generates Java source files (with the extension .java) that are then compiled into binary files (with the extension .class). The binary files contain bytecodes that can be interpreted by a Java VM. These files are usually called class files.