Class ComplDemo

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 ComplDemo
All Implemented Interfaces:
ActionListener, ComponentListener, ItemListener, MouseListener, MouseMotionListener, ImageObserver, MenuContainer, Serializable, Runnable, EventListener, Accessible

public class ComplDemo
extends Applet
implements MouseMotionListener, MouseListener, ActionListener, ItemListener, ComponentListener, Runnable

Demonstration of complex arithmetics.

The operations +, -, *, /, exp(), log() on complex numbers as well as many other operations can be comprehended graphically.

ComplDemo can be embedded as Applet into a HTML page as well as used as a stand-alone application.
As application:

                java ComplDemo
 resp.           java -jar ComplDemo.jar  
 or              javaw ComplDemo
 resp.           javaw -jar ComplDemo.jar
The last possibility, the start by jawaw.exe from an archive you get on most Windows JDK/JRE installations by double clicking on the .jar file.
As Applet: (example)
     <applet code="ComplDemo.class" archive="compldemo.jar" 
     alt="Complex Applet" name="Comp1" width="500" height="328"
     hspace="8" align="right">

For the Applet you can Hint: The last point will fail on some JRE=Java-plug-in / browser combinations. In that case you will have to put frame4j.jar as installed extension into the JRE used by the browser's Java-plug-in.

Hint 2: You may run this class as Applet by http://www.a-weinert.de/frame4j/downloads/compldemo.html.


© Copyright 1999 - 2002, 2005   Albrecht Weinert

Version:
11 (1.02.2010)
Author:
Albrecht Weinert
See Also:
Complex, CFun, Beans, Serialized Form

Nested Class Summary
 class ComplDemo.ComplexWrapper
          Wrapper for Complex with pixel coordinates and comparison.
 
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.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static String AUTHOR
          Information: author.
static String CLASS_F
          Information: class file name.
static String COPYRIGHT
          Information: copyright hint.
static int LAST_OP
          Last operator respectively function index.
static String[][] PAR_INFO
          Infos on Applet parameters.
 boolean showPi
          A circle of radius pi will be shown.
 boolean showUnit
          A circle of radius 1 will be shown.
static String TITLE
          Title for use as graphical application.
static String VERSION
          Informations: version and date.
 
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
ComplDemo()
           
 
Method Summary
 void actionPerformed(ActionEvent e)
           
 void componentHidden(ComponentEvent e)
           
 void componentMoved(ComponentEvent e)
           
 void componentResized(ComponentEvent e)
          Resize the frame if run as application.
 void componentShown(ComponentEvent e)
           
 void destroy()
          Final death as Applet.
 String getAppletInfo()
          Common informations on the Applet.
 Dimension getMinimumSize()
          Minimal size.
 String[][] getParameterInfo()
          Infos on Applet parameters.
 Dimension getPreferredSize()
          Size preferred.
 void imgInit()
          Initialising the background picture.
 void init()
          One time initialisations.
 void initOps()
          Set the operands to visible default values.
 void itemStateChanged(ItemEvent e)
          Item event.
static void main(String[] args)
          Start the graphical Demo as Java application.
 void makeArith()
          Do the arithmetic operation.
 void mouseClicked(MouseEvent e)
           
 void mouseDragged(MouseEvent e)
          Dragging the mouse.
 void mouseEntered(MouseEvent e)
           
 void mouseExited(MouseEvent e)
           
 void mouseMoved(MouseEvent e)
           
 void mousePressed(MouseEvent e)
          Pressing the mouse button.
 void mouseReleased(MouseEvent e)
           
 void paint(Graphics g)
          Pint the picture.
 void run()
          Working method of the background thread.
 void selectOp(int ts)
          Choosing another arithmetic operation.
 void showArith()
          Display "op1 op op2 = erg".
 void update(Graphics g)
          Paints itself (avoiding flicker).
 void updateOps()
          Make the operands and result consistent (pixel to Complex).
 
Methods inherited from class java.applet.Applet
getAccessibleContext, getAppletContext, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, 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, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, 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, 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, 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
 

Field Detail

TITLE

public static final String TITLE
Title for use as graphical application.

See Also:
Constant Field Values

AUTHOR

public static final String AUTHOR
Information: author.

See Also:
Constant Field Values

CLASS_F

public static final String CLASS_F
Information: class file name.

See Also:
Constant Field Values

VERSION

public static final String VERSION
Informations: version and date.

See Also:
Constant Field Values

COPYRIGHT

public static final String COPYRIGHT
Information: copyright hint.

See Also:
Constant Field Values

PAR_INFO

public static final String[][] PAR_INFO
Infos on Applet parameters.


LAST_OP

public static final int LAST_OP
Last operator respectively function index.

The operations are numbered from 1: + to 19: exp() .

See Also:
selectOp(int), Constant Field Values

showPi

public boolean showPi
A circle of radius pi will be shown.

default: true


showUnit

public boolean showUnit
A circle of radius 1 will be shown.

default: true

Constructor Detail

ComplDemo

public ComplDemo()
Method Detail

getParameterInfo

public String[][] getParameterInfo()
Infos on Applet parameters.

Overrides:
getParameterInfo in class Applet

getAppletInfo

public String getAppletInfo()
Common informations on the Applet.

Overrides:
getAppletInfo in class Applet

init

public void init()
One time initialisations.

Will be called once by the browser in the Applet life cycle or once by java.beans.Beans.instantiate() if run as Java application.

Overrides:
init in class Applet
See Also:
main(String[])

destroy

public void destroy()
Final death as Applet.

Overrides:
destroy in class Applet

run

public void run()
Working method of the background thread.

Specified by:
run in interface Runnable

imgInit

public void imgInit()
Initialising the background picture.

Hint: In run as application this method must be called conditionally on several spots.

Reasons:
  1. java.beans.Beans.instantiate() cannot create a picture in (Applet.) init() (Why not, the heck?),
  2. Running as an application allows dynamic resizing.


initOps

public void initOps()
Set the operands to visible default values.

op1 = (1, -1i)
op2 = (-1, -1i)


updateOps

public void updateOps()
Make the operands and result consistent (pixel to Complex).

This method makes the operands consistent after changes of the Complex or of the pixels. If the state is undefined a change of pixels is assumed for the operands.


update

public void update(Graphics g)
Paints itself (avoiding flicker).

Overrides:
update in class Container

paint

public void paint(Graphics g)
Pint the picture.

Overrides:
paint in class Container

mouseDragged

public void mouseDragged(MouseEvent e)
Dragging the mouse.

By dragging the mouse with left button pressed the caught operand's vector will be dragged and the painting, calculation and text display updated.

Specified by:
mouseDragged in interface MouseMotionListener

mousePressed

public void mousePressed(MouseEvent e)
Pressing the mouse button.

By pressing the (left) mouse button the operand nearer to the spot will be caught. (If an unary operation is selected, there is only one operand and hence no need to choose.)

Specified by:
mousePressed in interface MouseListener
See Also:
mouseDragged(java.awt.event.MouseEvent)

mouseMoved

public void mouseMoved(MouseEvent e)
Specified by:
mouseMoved in interface MouseMotionListener

mouseClicked

public void mouseClicked(MouseEvent e)
Specified by:
mouseClicked in interface MouseListener

mouseEntered

public void mouseEntered(MouseEvent e)
Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent e)
Specified by:
mouseExited in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent e)
Specified by:
mouseReleased in interface MouseListener

componentResized

public void componentResized(ComponentEvent e)
Resize the frame if run as application.

Specified by:
componentResized in interface ComponentListener

componentHidden

public void componentHidden(ComponentEvent e)
Specified by:
componentHidden in interface ComponentListener

componentMoved

public void componentMoved(ComponentEvent e)
Specified by:
componentMoved in interface ComponentListener

componentShown

public void componentShown(ComponentEvent e)
Specified by:
componentShown in interface ComponentListener

itemStateChanged

public void itemStateChanged(ItemEvent e)
Item event.

This leads to the choice of an (other) arithmetic operation by using selectOp(int).

Specified by:
itemStateChanged in interface ItemListener

selectOp

public void selectOp(int ts)
Choosing another arithmetic operation.

This method changes the arithmetic operation to be demonstrated. It might be called for demo Applets by buttons or by Java-Script.

For parameter values <= 0 nothing happens.

For parameter values > LAST_OP the operands will be initialised to default values by initOps().

For other values this applies:
1: +; 2: -; 3: *; 4: /; 5: exp; 6: re; 7: im 8: conj; 9: neg; 10: abs; 11: arg; 12: norm (abs*abs); 13: sin; 14: cos; 15: sinh; 16: cosh; 17: tan; 18: tanh; 19: log.


makeArith

public void makeArith()
Do the arithmetic operation.


showArith

public void showArith()
Display "op1 op op2 = erg".


actionPerformed

public void actionPerformed(ActionEvent e)
Specified by:
actionPerformed in interface ActionListener

getPreferredSize

public Dimension getPreferredSize()
Size preferred.

Returns (500, 328).

Overrides:
getPreferredSize in class Container

getMinimumSize

public Dimension getMinimumSize()
Minimal size.

Returns (480, 228).

Overrides:
getMinimumSize in class Container

main

public static void main(String[] args)
Start the graphical Demo as Java application.

The Applet ComplDemo will be embedded into a window of initial size 520 * 338.
The proceeding (recipe) is applicable for other Applets too.

Parameters:
args - not relevant