objectdraw
Class Controller

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by javax.swing.JApplet
                      extended by objectdraw.Controller
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer
Direct Known Subclasses:
FrameController, WindowController

public class Controller
extends JApplet

Controller is the class you should extend if you want to create an applet or window that contains your own custom GUI instead of a DrawingCanvas. It provides some helpful ObjectDraw features such as the begin() method, the startController() methods, and methods to load images and audio. Otherwise, it leaves you free to create whatever GUI you want.

Author:
Russell Zahniser (russell@zahniser.net)
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JApplet
JApplet.AccessibleJApplet
 
Nested classes/interfaces inherited from class java.applet.Applet
Applet.AccessibleApplet
 
Nested classes/interfaces inherited from class java.awt.Panel
Panel.AccessibleAWTPanel
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JApplet
accessibleContext, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Controller()
           
 
Method Summary
 void begin()
          Override this method to do whatever your controller needs to do to set up its GUI.
 AudioClip getAudio(String path)
          Load an audio file as an AudioClip.
 Image getImage(String path)
          Load an image file as an Image.
static String getVersion()
          Determine which version of ObjectDraw you are using.
 void hideGrid()
           
 boolean isGridVisible()
           
 void showGrid()
           
 void startController()
          Run this Controller in a new window 400 pixels by 400 pixels.
 void startController(int width, int height)
          Run this Controller in a new window of the specified size.
 void startController(int width, int height, String name)
          Run this Controller in a new window of the specified size.
 
Methods inherited from class javax.swing.JApplet
addImpl, createRootPane, getAccessibleContext, getContentPane, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isRootPaneCheckingEnabled, paramString, remove, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.applet.Applet
destroy, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, init, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start, stop
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Controller

public Controller()
Method Detail

begin

public void begin()
Override this method to do whatever your controller needs to do to set up its GUI.


getAudio

public AudioClip getAudio(String path)
Load an audio file as an AudioClip. Not all file formats are guaranteed to work; in particular, the version of Java on your computer may not know how to play .mp3 files, even if you have a separate mp3 player. The formats that should almost always work are .midi, .wav, and .au.

Parameters:
path - Path of the file, relative to the project directory. In other words, the sound file should be inside your project folder.
Returns:
An AudioClip representing the requested file. If no such file was found or it cannot be read, the return value will still be a valid AudioClip object (not null), but it will not play anything.

getImage

public Image getImage(String path)
Load an image file as an Image. The image formats that should almost always work are .png, .gif, and .jpg.

Parameters:
path - Path of the file, relative to the project directory. In other words, the image file should be inside your project folder.
Returns:
An Image representing the requested file. If no such file was found or it cannot be read, the return value will still be a valid Image object (not null), but it will be invisible or may even cause an error when shown.

getVersion

public static String getVersion()
Determine which version of ObjectDraw you are using.

Returns:
The ObjectDraw version, as a String.

hideGrid

public void hideGrid()

isGridVisible

public boolean isGridVisible()

showGrid

public void showGrid()

startController

public void startController()
Run this Controller in a new window 400 pixels by 400 pixels. This method allows you to create and run a controller from a main() method, so that you program can run as an application rather than an applet. It also makes it possible to create and run a controller interactively in BlueJ or DrJava.


startController

public void startController(int width,
                            int height)
Run this Controller in a new window of the specified size. This method allows you to create and run a controller from a main() method, so that you program can run as an application rather than an applet. It also makes it possible to create and run a controller interactively in BlueJ or DrJava.

Parameters:
width - width of applet
height - height of applet

startController

public void startController(int width,
                            int height,
                            String name)
Run this Controller in a new window of the specified size. This method allows you to create and run a controller from a main() method, so that you program can run as an application rather than an applet. It also makes it possible to create and run a controller interactively in BlueJ or DrJava.

Parameters:
width - width of applet
height - height of applet
name - name of window