Class FrameBufferPanel

  • All Implemented Interfaces:
    ImageObserver, MenuContainer, Serializable, Accessible

    public final class FrameBufferPanel
    extends JPanel
    This class is an interface between our renderer and the Java GUI system. This class allows our rendering code to be used as the primary renderer for Java programs. That is, this class allows us to write Java programs that use our renderer instead of the renderer built into Java's GUI library. Of course, our renderer will be much slower than the one built into Java (which uses the computer's GPU).

    A FrameBufferPanel "is a" JPanel. A FrameBufferPanel "has a" FrameBuffer. And a FrameBuffer "has a" array of pixel data. The pixel data in a FrameBuffer is put there by calling our rendering algorithms.

    Each instance of FrameBufferPanel has a reference to a FrameBuffer object and the FrameBuffer object determines the (preferred) dimensions of the FrameBufferPanel.

    A FrameBufferPanel should be instantiated by an application that uses our renderer. The application should initialize a Scene object with appropriate models and geometry. The application should then render the Scene into the FrameBuffer object contained in the FrameBufferPanel.

    This class is meant to be instantiated as a sub-panel of a JFrame. The JFrame may or may not implement event listeners. If the JFrame does implement event listeners, then the event listeners can make our renderer interactive.

    When a GUI event happens, any implemented event listener should update this FrameBufferPanel by modifying a Scene object appropriately and then having our renderer render the Scene object into this object's FrameBuffer. When the renderer is done updating the FrameBuffer, the event listener should call this object's Component.repaint() method, which will lead to the calling of this object's paintComponent(java.awt.Graphics) method, which will pass the FrameBuffer's pixel data to an Image that will be drawn on the Graphics context of the FrameBufferPanel (which is a JPanel). This will display the Image, which holds the FrameBuffer's contents, in the JPanel within a JFrame's window.

    This panel may be resizeable. When this panel resizes, its FrameBuffer object will also need to resize. But FrameBuffer objects cannot be resized. So each time this panel resizes, a new FrameBuffer object needs to be created. The ComponentListener.componentResized(java.awt.event.ComponentEvent) event handler from the ComponentListener interface should instantiate a new FrameBuffer object with the appropriate dimensions and then call this object's setFrameBuffer(renderer.framebuffer.FrameBuffer) method and pass it a reference to the new FrameBuffer object.

    See Also:
    Serialized Form