Class Text

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by Text
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class Text
extends JPanel

The Text class draws a String to the screen. It can show or hide the text, as well as an underline. Other options include changing the letter or underline color, and determining if the underline or text is visible or not. Although intended to be used for single letters, the Text class can be used to draw any length text to the screen. Note that showing/hiding the text and underline are independent. In other words, it is possible to display the text without the underline showing, display the underline without the text showing, show both, or show neither.

Version:
2012-11-15
Author:
Jerry Alan Fails and Emily Hill
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Component
Component.BaselineResizeBehavior
 
Field Summary
static int SPACE
           
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, 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
Text(String t)
          Initializes the text, sets the font, and sets the dimensions for this panel.
 
Method Summary
 Color getLetterColor()
          Returns the Color object used to determine the display color of the text.
 String getText()
          Returns the text string displayed by this text panel when shown.
 Color getUnderlineColor()
          Returns the Color object used to determine the display color of the underline.
 void hideText()
          Causes the text to be hidden the next time paintComponent(Graphics) is called.
 void hideUnderline()
          Causes the underline to be hidden the next time paintComponent(Graphics) is called.
 boolean isTextVisible()
          Returns true if the text will be shown the next time paintComponent(Graphics) is called.
 boolean isUnderlined()
          Returns true if the underline will be shown the next time paintComponent(Graphics) is called.
 boolean isWhiteSpace()
          Returns true if the text is whitespace consisting of spaces, tabs, or returns.
static void main(String[] args)
          Main method for testing.
 void paintComponent(Graphics page)
          Draws the text panel to the screen based on the field values.
 void setLetterColor(Color letterColor)
          Sets the display color used when drawing the text.
 void setText(String t)
          Sets the text to be displayed by this object.
 void setUnderlineColor(Color underlineColor)
          Sets the display color used when drawing the underline.
 void showText()
          Causes the text to be shown the next time paintComponent(Graphics) is called.
 void showUnderline()
          Causes the underline to be shown the next time paintComponent(Graphics) is called.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, 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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SPACE

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

Text

public Text(String t)
Initializes the text, sets the font, and sets the dimensions for this panel.

Parameters:
t - the text string to be displayed by this text panel
Method Detail

setText

public void setText(String t)
Sets the text to be displayed by this object.

Parameters:
t - the text string to be displayed by this text panel

getText

public String getText()
Returns the text string displayed by this text panel when shown.

Returns:
the text string displayed by this text panel

isWhiteSpace

public boolean isWhiteSpace()
Returns true if the text is whitespace consisting of spaces, tabs, or returns. Returns false otherwise.

Returns:
true if the text is currently whitespace, false otherwise.

showText

public void showText()
Causes the text to be shown the next time paintComponent(Graphics) is called.


hideText

public void hideText()
Causes the text to be hidden the next time paintComponent(Graphics) is called.


isTextVisible

public boolean isTextVisible()
Returns true if the text will be shown the next time paintComponent(Graphics) is called. This method returns false if the text will be invisible.

Returns:
true if the text will be shown, false otherwise.

showUnderline

public void showUnderline()
Causes the underline to be shown the next time paintComponent(Graphics) is called.


hideUnderline

public void hideUnderline()
Causes the underline to be hidden the next time paintComponent(Graphics) is called.


isUnderlined

public boolean isUnderlined()
Returns true if the underline will be shown the next time paintComponent(Graphics) is called. This method returns false if the underline will be invisible.

Returns:
true if the underline will be shown, false otherwise.

getLetterColor

public Color getLetterColor()
Returns the Color object used to determine the display color of the text. Note the color is independent of whether the text will be visible or hidden.

Returns:
the display color of the text

setLetterColor

public void setLetterColor(Color letterColor)
Sets the display color used when drawing the text.

Parameters:
letterColor - the Color object to be used

getUnderlineColor

public Color getUnderlineColor()
Returns the Color object used to determine the display color of the underline. Note the color is independent of whether the underline will be visible or hidden.

Returns:
the display color of the underline

setUnderlineColor

public void setUnderlineColor(Color underlineColor)
Sets the display color used when drawing the underline.

Parameters:
underlineColor - the Color object to be used

paintComponent

public void paintComponent(Graphics page)
Draws the text panel to the screen based on the field values.

Overrides:
paintComponent in class JComponent

main

public static void main(String[] args)
Main method for testing.

Parameters:
args - none necessary