public abstract class ConsoleProgram extends AbstractConsoleProgram
Program
that installs a console in the window.JApplet.AccessibleJApplet
Applet.AccessibleApplet
Panel.AccessibleAWTPanel
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
PROGRAM_COMPLETED_TITLE_SUFFIX
CONFIG_FILE_NAME, invisibleObjects
accessibleContext, rootPane, rootPaneCheckingEnabled
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
ConsoleProgram()
Creates a new console program.
|
Modifier and Type | Method and Description |
---|---|
void |
captureOutput() |
void |
captureOutput(boolean capture) |
protected IOConsole |
createConsole()
Creates the console used by the
ConsoleProgram . |
void |
echoComments()
Print all echoed comments from the input override file onscreen.
|
String |
getCapturedOutput() |
String |
getComments()
Print all echoed comments from the input override file onscreen.
|
void |
init()
Specifies the code to be executed as startup time before the
run method is called. |
void |
overrideInput(InputStream stream)
Signals the ConsoleProgram to use the input profile read from the given stream,
rather than prompt the user for input.
|
void |
overrideInput(Reader reader)
Signals the ConsoleProgram to use the input profile read from the given reader,
rather than prompt the user for input.
|
void |
overrideInput(String inputFilename)
Signals the ConsoleProgram to use the input profile read from the file
with inputFilename, rather than prompt the user for input.
|
void |
print(String value)
Displays the argument value on the console, leaving the cursor at the end of
the output.
|
void |
print(String value,
Color color)
Prints the given string in the given color.
|
void |
printf(String format,
Object... args)
Writes a formatted string to this output stream using the specified format string and arguments.
|
void |
println()
Advances the console cursor to the beginning of the next line.
|
void |
println(String value)
Displays the argument value on the console and then advances the cursor
to the beginning of the next line.
|
void |
println(String value,
Color color)
Prints the given string in the given color and then advances the cursor to the beginning of the next line.
|
boolean |
readBoolean(String prompt,
String y,
String n)
Prompts the user to enter a boolean value, which is matched against the
labels provided.
|
double |
readDouble(String prompt,
double min,
double max)
Prompts the user to enter an double-precision number, which is then returned
as the value of this method.
|
int |
readInt(String prompt,
int min,
int max)
Prompts the user to enter an integer, which is then returned as the value
of this method.
|
String |
readLine(String prompt)
Prompts the user for a line of input.
|
void |
run()
Specifies the code to be executed as the program runs.
|
checkCompilerFlags, clearConsole, compareOutput, endHook, fontEnlarge, fontShrink, fontToggleBold, getAllOutput, getFont, historyDown, historyUp, loadConfiguration, loadInputScript, menuAction, mouseWheelMoved, promptUserForFile, promptUserForFile, promptUserForFile, saveConfiguration, scrollLineDown, scrollLineUp, scrollPageDown, scrollPageUp, scrollToBottom, scrollToTop, setClearConsoleEnabled, setColorFromChooser, setFont, setFont, setFontFromChooser
actionPerformed, add, addActionListeners, addActionListeners, addActionListenersToButtonsOnly, addAllActionListeners, addExitHook, addImpl, adjustmentValueChanged, alert, alert, animation, center, changedUpdate, checkKill, checkStartupSettings, componentAdded, componentHidden, componentMoved, componentRemoved, componentResized, componentShown, confirm, contentsChanged, createDialogIO, createMenuBar, createParameterTable, createProgramFrame, destroy, error, error, error, exit, fileExists, fileExists, fileExistsInsideJAR, fileExistsInsideJAR, fileExistsOnDisk, fileExistsOnDisk, fileSize, fileSize, focusGained, focusLost, getAnimationDelay, getAppletStub, getArgumentArray, getBoolean, getBoolean, getBoolean, getBorder, getBottomY, getCenterLocation, getCenterX, getCenterY, getCentralRegionSize, getConsole, getDialog, getDouble, getDouble, getDouble, getDouble, getHeight, getInputModel, getInteger, getInteger, getInteger, getInteger, getJFrame, getLayout, getLine, getLine, getMainThread, getMenuBar, getOutputColor, getOutputModel, getParameter, getParameterTable, getPreferredSize, getReader, getReal, getReal, getReal, getReal, getRegionPanel, getRightX, getScreenHeight, getScreenSize, getScreenWidth, getStartupObject, getTitle, getWidth, getWindow, getWriter, getYesOrNo, hasConfiguration, insertUpdate, intervalAdded, intervalRemoved, isAnimated, isApplet, isAppletMode, isExitOnClose, isInitialized, isStarted, itemStateChanged, keyPressed, keyReleased, keyTyped, killMe, loadConfiguration, main, menuCanceled, menuDeselected, menuSelected, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, openFile, openFile, openFileFromDisk, openFileFromDisk, openFileFromJAR, openFileFromJAR, pack, pause, pauseTick, popupMenuCanceled, popupMenuWillBecomeInvisible, popupMenuWillBecomeVisible, print, print, print, print, print, print, print, print, print, print, print, print, print, print, println, println, println, println, println, println, println, println, println, println, println, println, println, println, prompt, readBoolean, readBoolean, readDouble, readDouble, readDouble, readInt, readInt, readInt, readLine, remove, remove, removeAll, removeFromRegion, removeMenuBar, removeUpdate, repaint, runHook, saveConfiguration, setAnimated, setAnimationDelay, setAppletStub, setBackground, setBottomY, setCenterLocation, setCenterX, setCenterY, setConsole, setDialog, setExitOnClose, setFramesPerSecond, setHeight, setInputModel, setInvisible, setJFrame, setJMenuBar, setLayout, setLocation, setLocation, setOutputColor, setOutputModel, setParameter, setParameterTable, setPauseScaleFactor, setResizable, setRightX, setShowPixelGrid, setShowPixelInfo, setSize, setStartupObject, setTitle, setWidth, setX, setY, showErrorMessage, start, start, startAnimation, startHook, startRun, stateChanged, stopAnimation, textValueChanged, validate, valueChanged, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowGainedFocus, windowIconified, windowLostFocus, windowOpened, windowStateChanged
createRootPane, getAccessibleContext, getContentPane, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isRootPaneCheckingEnabled, paramString, repaint, setContentPane, setGlassPane, setLayeredPane, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameterInfo, isActive, isValidateRoot, newAudioClip, play, play, resize, resize, setStub, showStatus, stop
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, getListeners, getMaximumSize, getMinimumSize, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, transferFocusDownCycle, validateTree
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, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, 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, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, revalidate, 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, transferFocusBackward, transferFocusUpCycle
public ConsoleProgram()
public void run()
run
method is required for applications that have
a thread of control that runs even in the absence of user actions,
such as a program that uses console interation or that involves
animation. GUI-based programs that operate by setting up an initial
configuration and then wait for user events usually do not specify a
run
method and supply a new definition for init
instead.public void init()
run
method is called. Subclasses can override this
method to perform any initialization code that would ordinarily
be included in an applet init
method. In general,
subclasses will override init
in GUI-based programs
where the program simply sets up an initial state and then waits
for events from the user. The run
method is required
for applications in which there needs to be some control thread
while the program runs, as in a typical animation.init
in interface ProgramInterface
init
in class Program
protected IOConsole createConsole()
ConsoleProgram
.createConsole
in class Program
public void overrideInput(String inputFilename)
inputFilename
- File to draw the input from.public void overrideInput(InputStream stream)
inputFilename
- File to draw the input from.public void overrideInput(Reader reader)
inputFilename
- File to draw the input from.public void captureOutput()
public void captureOutput(boolean capture)
public String getCapturedOutput()
public void echoComments()
public String getComments()
public void print(String value)
Program
print
method is overloaded so that
value
can be of any type.print
in interface acm.io.IOModel
print
in interface ProgramInterface
print
in class Program
value
- The value to be displayedpublic void print(String value, Color color)
Program
public void printf(String format, Object... args)
Program
printf
in interface ProgramInterface
printf
in class Program
format
- A format string as described in Java's Format string syntax.args
- Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by The Javaâ„¢ Virtual Machine Specification. The behavior on a null argument depends on the conversion.public void println()
Program
println
in interface acm.io.IOModel
println
in interface ProgramInterface
println
in class Program
public void println(String value)
Program
println
method is
overloaded so that value
can be of any type.println
in interface acm.io.IOModel
println
in interface ProgramInterface
println
in class Program
value
- The value to be displayedpublic void println(String value, Color color)
Program
public int readInt(String prompt, int min, int max)
Program
low
and high
. If the user types a value that
is not a legal integer or is outside the specified range, the method
ordinarily offers the user a chance to reenter the data,
although this behavior can be changed using the
setExceptionOnError
method.readInt
in interface acm.io.IOModel
readInt
in class Program
prompt
- The prompt string to display to the usermin
- The lowest value in the permitted rangemax
- The highest value in the permitted rangepublic double readDouble(String prompt, double min, double max)
Program
low
and high
. If the user types a value
that is not a legal number, the method ordinarily offers the user a chance
to reenter the data, although this behavior can be changed using the
setExceptionOnError
method.readDouble
in interface acm.io.IOModel
readDouble
in class Program
prompt
- The prompt string to display to the usermin
- The lowest value in the permitted rangemax
- The highest value in the permitted rangedouble
public boolean readBoolean(String prompt, String y, String n)
Program
readBoolean
ordinarily offers the user a chance
to reenter the data, although this behavior can be changed using the
setExceptionOnError
method.readBoolean
in interface acm.io.IOModel
readBoolean
in class Program
prompt
- The prompt string to display to the usery
- The string used to indicate true
n
- The string used to indicate false