edu.uah.math.devices
Class Door

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by edu.uah.math.devices.Door
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class Door
extends javax.swing.JComponent
implements java.io.Serializable

This class defines a door that can be opened or closed. When closed, the door shows a label; when opened the door shows an image and a label. The object comes supplied with car and goat images, suitable for the Monty Hall problem.

Version:
August, 2003
Author:
Kyle Siegrist, Dawn Duehring
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int CAR
           
static int GOAT
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
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
Door()
          This default constructor creates a new door with default size 150 by 200 and with default door color yellow, open color white, and label color red.
Door(int w, int h)
          This special constructor creates a new door with specified height and width and with default door color yellow, open color white, and label color red.
Door(int w, int h, java.awt.Color dc, java.awt.Color oc, java.awt.Color lc)
          This general constructor creates a new door with width and height, and specified colors.
 
Method Summary
 void close(java.lang.String s)
          This method closes the door to display a specified caption.
 java.awt.Color getDoorColor()
          This method returns the door color
 java.awt.Image getImage()
          This method returns the image.
 java.lang.String getLabel()
          This method returns the label.
 java.awt.Color getLabelColor()
          This method returns the label color
 java.awt.Dimension getMinimumSize()
          This method specifies the minimum size.
 java.awt.Color getOpenColor()
          This method returns the open color
 java.awt.Dimension getPreferredSize()
          This method specifies the preferred size.
 boolean isOpened()
          This method tests to see if the door is opened.
 void open(java.awt.Image i, java.lang.String s)
          This method opens the door to display a specified image and caption.
 void open(int i, java.lang.String s)
          This method opens the door to display one of the standard images (the car or the goat) and a caption
 void paintComponent(java.awt.Graphics g)
          This method paints the door.
 void setDoorColor(java.awt.Color c)
          This method sets the door color.
 void setImage(java.awt.Image i)
          This method sets the image.
 void setImage(int i)
          This method sets the image to one of the standard images (car or goat).
 void setLabel(java.lang.String s)
          This method sets the label.
 void setLabelColor(java.awt.Color c)
          This method sets the label color.
 void setOpenColor(java.awt.Color c)
          This method sets the open color.
 void setOpened(boolean b)
          This method set the open state of the door.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, 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

GOAT

public static final int GOAT
See Also:
Constant Field Values

CAR

public static final int CAR
See Also:
Constant Field Values
Constructor Detail

Door

public Door(int w,
            int h,
            java.awt.Color dc,
            java.awt.Color oc,
            java.awt.Color lc)
This general constructor creates a new door with width and height, and specified colors. The width and height should be chosen according to the size of the images to be supplied.

Parameters:
w - the width
h - the height
dc - door color
oc - open color
lc - label color

Door

public Door(int w,
            int h)
This special constructor creates a new door with specified height and width and with default door color yellow, open color white, and label color red.

Parameters:
w - the width
h - the height

Door

public Door()
This default constructor creates a new door with default size 150 by 200 and with default door color yellow, open color white, and label color red.

Method Detail

open

public void open(java.awt.Image i,
                 java.lang.String s)
This method opens the door to display a specified image and caption.

Parameters:
i - the image
s - the label

open

public void open(int i,
                 java.lang.String s)
This method opens the door to display one of the standard images (the car or the goat) and a caption

Parameters:
i - the index (0 goat, 1 car)
s - the caption

close

public void close(java.lang.String s)
This method closes the door to display a specified caption.

Parameters:
s - the label.

setImage

public void setImage(java.awt.Image i)
This method sets the image. The state of the door is not changed.

Parameters:
i - the image

setImage

public void setImage(int i)
This method sets the image to one of the standard images (car or goat). The state of the door is not changed.


getImage

public java.awt.Image getImage()
This method returns the image. The state of the door is not changed.

Returns:
the image.

setLabel

public void setLabel(java.lang.String s)
This method sets the label. The state of the door is not changed.

Parameters:
s - the string

getLabel

public java.lang.String getLabel()
This method returns the label. The state of the door is not changed.

Returns:
the label

paintComponent

public void paintComponent(java.awt.Graphics g)
This method paints the door.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - the graphics context.

setOpened

public void setOpened(boolean b)
This method set the open state of the door.

Parameters:
b - true if the door is to be opened

isOpened

public boolean isOpened()
This method tests to see if the door is opened.

Returns:
true if opened, false if closed.

setDoorColor

public void setDoorColor(java.awt.Color c)
This method sets the door color.

Parameters:
c - the door color

getDoorColor

public java.awt.Color getDoorColor()
This method returns the door color

Returns:
the door color

setOpenColor

public void setOpenColor(java.awt.Color c)
This method sets the open color.

Parameters:
c - the open color

getOpenColor

public java.awt.Color getOpenColor()
This method returns the open color

Returns:
the open color

setLabelColor

public void setLabelColor(java.awt.Color c)
This method sets the label color.

Parameters:
c - the label color

getLabelColor

public java.awt.Color getLabelColor()
This method returns the label color

Returns:
the label color

getMinimumSize

public java.awt.Dimension getMinimumSize()
This method specifies the minimum size.

Overrides:
getMinimumSize in class javax.swing.JComponent
Returns:
the 100 by 300 dimension

getPreferredSize

public java.awt.Dimension getPreferredSize()
This method specifies the preferred size.

Overrides:
getPreferredSize in class javax.swing.JComponent
Returns:
the 100 by 300 dimension