Class | Tree | Deprecated | Index | Help
PREV | NEXT SHOW LISTS | HIDE LISTS

Class Calculator.CalculatorGUI

java.lang.Object
    |
    +----java.awt.Component
            |
            +----java.awt.Container
                    |
                    +----java.awt.Window
                            |
                            +----java.awt.Frame
                                    |
                                    +----Calculator.CalculatorGUI

public class CalculatorGUI
extends java.awt.Frame
implements Calculator
This is an implementation of the GUI for a basic four-function calculator. It relies on a ButtonHandler (Runnable) to repeatedly call getButton() and consume the buttonIDs that the Calculator object produces.

This follows the interactive-control-loop design described in the early parts of 6.096 and as a part of the Rethinking CS101 project of Lynn Andrea Stein's AP Group at the MIT Artificial Intelligence Laboratory.

See Also:
ButtonHandler, cs101.util.IntBuffer

Fields inherited from class java.awt.Frame
 CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Component
 BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 

Constructor Summary
 CalculatorGUI()
Initialize components and such at runtime.
 

Method Summary
int  getButton()
Get the next Button pressed.
java.lang.String  getButtonLabel(int buttonID)
Get the label for the given Button ID.
java.lang.String  getText()
Get the text currently displayed on the Calculator.
void  setText(java.lang.String newText)
Set the text currently displayed on the Calculator.
 
Methods inherited from class java.awt.Frame
 addNotify, dispose, getCursorType, getFrames, getIconImage, getMenuBar, getTitle, isResizable, remove, setCursor, setIconImage, setMenuBar, setResizable, setTitle
 
Methods inherited from class java.awt.Window
 addNotify, addWindowListener, dispose, getFocusOwner, getInputContext, getLocale, getOwnedWindows, getOwner, getToolkit, getWarningString, isShowing, pack, postEvent, removeWindowListener, show, toBack, toFront
 
Methods inherited from class java.awt.Container
 add, add, add, add, add, addContainerListener, addNotify, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, remove, removeAll, removeContainerListener, removeNotify, setLayout, update, validate
 
Methods inherited from class java.awt.Component
 action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, deliverEvent, disable, dispatchEvent, doLayout, enable, enable, enableInputMethods, getAlignmentX, getAlignmentY, getBackground, getBounds, getColorModel, getComponentAt, getComponentAt, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getParent, getPeer, getPreferredSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, update, validate
 
Methods inherited from class java.lang.Object
 equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CalculatorGUI

public CalculatorGUI()
Initialize components and such at runtime. Automagically called by the java runtime. You should not use it.
Method Detail

getButton

public int getButton()
Get the next Button pressed. The return value will be an int between 0 and 9 (if the button was a number) or one of the Calculator constants.
Implements:
getButton in interface Calculator
Returns:
the next button to be handled.

getButtonLabel

public java.lang.String getButtonLabel(int buttonID)
Get the label for the given Button ID. The argument should be an int between 0 and 9 (if the button was a number) or one of the Calculator constants, otherwise the empty string ("") will be returned.
Implements:
getButtonLabel in interface Calculator
Returns:
the button label as a String.

getText

public java.lang.String getText()
Get the text currently displayed on the Calculator.
Implements:
getText in interface Calculator
Returns:
the text as a String.

setText

public void setText(java.lang.String newText)
Set the text currently displayed on the Calculator.
Implements:
setText in interface Calculator
Parameters:
newText - the text to be displayed.

Class | Tree | Deprecated | Index | Help
PREV | NEXT SHOW LISTS | HIDE LISTS