Open Java – The General Idea

 

Introduction:

 

The purpose of OJ is to create a means for Java multimedia programmers to share code.  OJ is a loosely connected system of components, but more important, it’s an example of how to write component-based programs.  Through a component approach programmers can write smaller pieces of code, focus on their specialty, and connect their code lego block style with components written by others.

 

The problem:

 

When java artist/programmers look online for source code they find that most of the demo and sample Java code is embedded into larger programs.  The code may be open source, but to reuse a part of it, the programmer has to hack code out of the larger program.  The functionality that the programmer is looking for is embedded directly into specific contexts, ie. physics simulation code may be embedded into an Applet paint function.  Most programmers don’t write components probably because there is no foundation of useable components to build upon.

 

OJ Goals:

 

1) Create a method for building small code components that can be reused in a variety of contexts. 

2) Provide sample components that demonstrate a pluggable approach to code design.

3) Provide a context independent framework for running components, ie. a way to “test drive” a component outside of any specific application. 

4) Identify the major areas of application development (ie. screen output, file IO, mouse/keyboard input) and demonstrate how components in each area can communicate with components in other areas.

 

The OJ approach:

 

1) Make Panels instead of applets, applications, frames, jframes, etc.  Panels can be easily displayed in any context (applet, app, frame, dialog, window), and are not tied to any one context.

2) Hide context specific functions.  The OJToolkit class wraps context sensitive functions like opening files, reading command line parameters, etc.  By calling functions in OJToolkit, components can function identically in both Applet and Application contexts.

3) Provide classes for commonly used functionality (panels, threads, graphics, property files).

4) Write components that have one responsibility.  For instance, a component that performs file IO should not also render graphics.  A graphic renderer should not perform physics calculations.

 

The basic pieces:

 

Because OJ code is built on Panels, not applets, the OJ system provides generic applet and app classes to load and display OJPanels either on a web page or in a window.  OJApp and OJApplet take a panel name as a parameter.  They use OJToolkit to configure the panel in a context independent fashion.

 

OJApp  |  OJApplet    

-- load, display and run an OJPanel

-- load a properties file to configure the panel

 

OJToolkit

-- hide context specific functions

-- hold system settings, properties, and command line parameters

 

OJPanel

-- main panel contains application functionality

-- programmer extends this class to build their own app

 

oj.jar

-- small archive file contains a foundation of useful components

-- this is the only file that needs to be included in order to use the OJ system