maclib
Class DrawingApplet

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 maclib.DrawingApplet
All Implemented Interfaces:
java.awt.event.ComponentListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class DrawingApplet
extends java.applet.Applet
implements java.awt.event.ComponentListener

A DrawingApplet is used for a drawing panel and it is associated with a DrawingStuff object that provides automatic repaint, using an off-screen image. The DrawingStuff also implements listeners for handling keyboard and mouse events that concern the DrawingApplet.

A subclass of DrawingApplet may be instanciated directly as an applet. In this case, a GrafPort object is also allocated and it provides an interface for QuickDraw-like drawing and event routines. This GrafPort is available by a call to the getPort() method. Any subclass of DrawingApplet that overrides the init(), destroy() or paint(Graphics) methods, should call these in turn to provides suitable working. The start() method does nothing and any subclass of DrawingApplet should override it.

A DrawingApplet object is also instanciated during the explicit initialization of a GrafPort. In that case the DrawingApplet is set as the component of a DrawingFrame and it doesn't need direct control.

Version:
01 mar 2005
Author:
Philippe Chassignet, Ecole Polytechnique
See Also:
DrawingStuff, GrafPort, DrawingFrame, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.BaselineResizeBehavior
 
Field Summary
 
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
DrawingApplet()
          The default constructor for a DrawingApplet used as an applet.
 
Method Summary
 void componentHidden(java.awt.event.ComponentEvent e)
          Invoked when the panel has been hidden.
 void componentMoved(java.awt.event.ComponentEvent e)
          Invoked when the panel has been moved.
 void componentResized(java.awt.event.ComponentEvent e)
          Invoked when the panel has been resized.
 void componentShown(java.awt.event.ComponentEvent e)
          Invoked when the panel has been made visible.
 void destroy()
          The destroy method as for any applet.
 void dispose()
          Disposes of this DrawingApplet.
 void finalize()
          Called by the garbage collector when there are no more reference to this DrawingApplet.
 java.lang.String getAppletInfo()
          Returns a string giving informations about this DrawingApplet.
 GrafPort getPort()
          Returns the GrafPort object that provides QuickDraw-like drawing and event routines onto this panel.
 java.awt.Dimension getPreferredSize()
           
 DrawingStuff getStuff()
          Returns the attached DrawingStuff object that provides drawings with automatic repaint and interfaces for keyboard and mouse events.
 boolean imageUpdate(java.awt.Image img, int flags, int x, int y, int width, int height)
          Repaints the panel when the image has changed.
 void init()
          The init method as for any applet.
 void paint(java.awt.Graphics g)
          Invoked by the event handler when this panel needs to be repaint.
 void prefSize(java.awt.Dimension size)
           
 void start()
          The start method as for any applet.
 void stop()
          The stop method as for any applet.
 void update(java.awt.Graphics g)
           
 
Methods inherited from class java.applet.Applet
getAccessibleContext, getAppletContext, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus
 
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, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, 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, 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, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, 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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DrawingApplet

public DrawingApplet()
The default constructor for a DrawingApplet used as an applet. A GrafPort will be later allocated during the call to the init() method.

See Also:
init()
Method Detail

init

public void init()
The init method as for any applet. It is called by the browser or applet viewer to inform this applet that it has been loaded into the system. It is always called before the first time that the start() method is called.

Any subclass of DrawingApplet that overrides this method, should call this in turn to provides suitable initialization.

Overrides:
init in class java.applet.Applet
See Also:
Applet.init()

start

public void start()
The start method as for any applet. Called by the browser or applet viewer to inform this applet that it should start its execution. It is called after the init() method and each time the applet is revisited in a Web page.

This method does nothing and any subclass of DrawingApplet should override it, to perform any drawings each time the Web page containing it is visited.

Overrides:
start in class java.applet.Applet
See Also:
Applet.start()

stop

public void stop()
The stop method as for any applet. Called by the browser or applet viewer to inform this applet that it should stop its execution. It is called when the Web page that contains this applet has been replaced by another page, and also just before the applet is to be destroyed.

This method does nothing and any subclass of DrawingApplet has to override it, when stop processing is needed.

Overrides:
stop in class java.applet.Applet
See Also:
Applet.stop()

destroy

public void destroy()
The destroy method as for any applet. Called by the browser or applet viewer to inform this applet that it is being reclaimed and that it should destroy any resources that it has allocated. The stop() method will always be called before destroy().

Any subclass of DrawingApplet that overrides this method, should call this in turn to provides suitable memory cleaning.

Overrides:
destroy in class java.applet.Applet
See Also:
Applet.destroy()

getAppletInfo

public java.lang.String getAppletInfo()
Returns a string giving informations about this DrawingApplet.

Any subclass of DrawingApplet that overrides this method, should include this one.

Overrides:
getAppletInfo in class java.applet.Applet
Returns:
the string of informations

getStuff

public DrawingStuff getStuff()
Returns the attached DrawingStuff object that provides drawings with automatic repaint and interfaces for keyboard and mouse events.

Returns:
the DrawingStuff object

getPort

public GrafPort getPort()
Returns the GrafPort object that provides QuickDraw-like drawing and event routines onto this panel.

Returns:
the GrafPort object

dispose

public void dispose()
Disposes of this DrawingApplet. This method must be called to release the resources.


finalize

public void finalize()
Called by the garbage collector when there are no more reference to this DrawingApplet.

Overrides:
finalize in class java.lang.Object

prefSize

public void prefSize(java.awt.Dimension size)

getPreferredSize

public java.awt.Dimension getPreferredSize()
Overrides:
getPreferredSize in class java.awt.Container

paint

public void paint(java.awt.Graphics g)
Invoked by the event handler when this panel needs to be repaint. It results in copying the content of the attached off-screen image.

Any subclass of DrawingApplet that overrides this method, should call this in turn to provides suitable update.

Overrides:
paint in class java.awt.Container
Parameters:
g - the specified Graphics object for painting onto this panel

update

public void update(java.awt.Graphics g)
Overrides:
update in class java.awt.Container

componentResized

public void componentResized(java.awt.event.ComponentEvent e)
Invoked when the panel has been resized.

Specified by:
componentResized in interface java.awt.event.ComponentListener

componentMoved

public void componentMoved(java.awt.event.ComponentEvent e)
Invoked when the panel has been moved.

Specified by:
componentMoved in interface java.awt.event.ComponentListener

componentShown

public void componentShown(java.awt.event.ComponentEvent e)
Invoked when the panel has been made visible.

Specified by:
componentShown in interface java.awt.event.ComponentListener

componentHidden

public void componentHidden(java.awt.event.ComponentEvent e)
Invoked when the panel has been hidden.

Specified by:
componentHidden in interface java.awt.event.ComponentListener

imageUpdate

public boolean imageUpdate(java.awt.Image img,
                           int flags,
                           int x,
                           int y,
                           int width,
                           int height)
Repaints the panel when the image has changed. Should override the Component method that only calls repaint().

Specified by:
imageUpdate in interface java.awt.image.ImageObserver
Overrides:
imageUpdate in class java.awt.Component