ch.aplu.gidlet
Class MConsole

java.lang.Object
  extended by javax.microedition.lcdui.Displayable
      extended by javax.microedition.lcdui.Canvas
          extended by ch.aplu.gidlet.MConsole

public class MConsole
extends javax.microedition.lcdui.Canvas

Full screen text window containing lines of text, simulating Java's System.out.println.

Each line may have an individual color. No text cursor is shown. If the number of displayed lines exceeds the height of the display, the text may be vertically scrolled by using the up/down keys and horizontally scrolled by using the left/right keys.

Newline character \n may be inserted to start a new line, other non-printing characters should not be used.

More than one instance may be created. The constructor flag visible may be used, to select if the display is initially shown or hidden. A hidden display will become visible by calling show(). There is no other way to make it hidden than displaying a different display. print/println may be called while the display is hidden.

A soft button 'Exit' is shown. Hitting the corresponding key will call the Gidlet's doExit(). If you do not need this button, invoke removeExitButton().

If you implement your own CommandListener and call setCommandListener(), the internal CommandListener is disabled.

print() and println() are overloaded for all primitive data types.

main() serves as entry point for the user programm. It is called in the run-method of a separate thread and should terminate to avoid non-terminated threads.

A global instance of MConsole may be created while declaring application instance variables. To garantee that the initialization is executed in the Gidlet's thread, these instances are queued and the intialisation takes place in the same order they are created when main() is started.


Field Summary
 
Fields inherited from class javax.microedition.lcdui.Canvas
DOWN, FIRE, GAME_A, GAME_B, GAME_C, GAME_D, KEY_NUM0, KEY_NUM1, KEY_NUM2, KEY_NUM3, KEY_NUM4, KEY_NUM5, KEY_NUM6, KEY_NUM7, KEY_NUM8, KEY_NUM9, KEY_POUND, KEY_STAR, LEFT, RIGHT, UP
 
Constructor Summary
MConsole()
          Contructs a MConsole with unlimited number of lines, black background, white default text color and large size of font.
MConsole(boolean visible)
          Contructs a MConsole with unlimited number of lines, black background, white default text color and large size of font.
MConsole(int nbLines, int bgColor, int textColor, int fontSize)
          Constructs a MConsole with given maximal number of lines in text buffer, the background color, the default text color and the size of the font (1: small, 2: medium, 3: large)
If nbLines <= 0, the number of lines is unlimited.
MConsole(int nbLines, int bgColor, int textColor, int fontSize, boolean visible)
          Constructs a MConsole with given maximal number of lines in text buffer, the background color, the default text color and the size of the font (1: small, 2: medium, 3: large)
If nbLines <= 0, the number of lines is unlimited.
 
Method Summary
 void addOkButton()
          Adds an OK soft button with label "OK".
 void addOkButton(java.lang.String label)
          Adds an OK soft button with given label.
 void clear()
          Erases all text and show empty console.
 void clear(int bgColor, int textColor)
          Erases all text and show empty console and sets background and text colors.
 void color(int textColor)
          Changes default text color to given color.
protected  void init()
          Initialize MConsole.
protected  void keyPressed(int key)
          Notificaton of key pressed.
protected  void keyReleased(int key)
          Notification of key release.
protected  void keyRepeated(int key)
          Notification of key repeated.
protected  void paint(javax.microedition.lcdui.Graphics g)
          Used for rendering canvas.
 void print(boolean b)
          Prints a boolean.
 void print(char ch)
          Prints a character.
 void print(char[] s)
          Prints a array of characters.
 void print(double d)
          Prints a double-precision floating-point number.
 void print(float f)
          Prints a floating-point number.
 void print(int i)
          Prints an integer.
 void print(long l)
          Prints a long integer.
 void print(java.lang.String text)
          Appends given text to last line, if print() was previously called or start a new line, if no print-method or println() was previously called.
 void println()
          Starts a new line.
 void println(boolean b)
          Prints a boolean and advances on next line.
 void println(char ch)
          Prints a character and advances on next line.
 void println(char[] s)
          Prints an array of characters and advances on next line.
 void println(double d)
          Prints a double-precision floating-point number and advances on next line.
 void println(float f)
          Prints a floating-point number and advances on next line.
 void println(int i)
          Prints an integer and advances on next line.
 void println(long l)
          Prints a long integer and advances on next line.
 void println(java.lang.String text)
          Appends given text to last line, if print() was previously called or start a new line, if no print-method or println() was previously called.
 void removeExitButton()
          Removes Exit soft button.
 void removeOkButton()
          Removes Ok soft button.
 void show()
          Shows the form display if it is not yet visible or it was previously hidden by another display.
 void show(boolean wait)
          Shows the console display if it was previously hidden by another display or not yet displayed.
 
Methods inherited from class javax.microedition.lcdui.Canvas
getGameAction, getKeyCode, getKeyName, hasPointerEvents, hasPointerMotionEvents, hasRepeatEvents, hideNotify, isDoubleBuffered, pointerDragged, pointerPressed, pointerReleased, repaint, repaint, serviceRepaints, setCommandListener, setFullScreenMode, showNotify, sizeChanged
 
Methods inherited from class javax.microedition.lcdui.Displayable
addCommand, getHeight, getTicker, getTitle, getWidth, isShown, removeCommand, setTicker, setTitle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MConsole

public MConsole(int nbLines,
                int bgColor,
                int textColor,
                int fontSize,
                boolean visible)
Constructs a MConsole with given maximal number of lines in text buffer, the background color, the default text color and the size of the font (1: small, 2: medium, 3: large)
If nbLines <= 0, the number of lines is unlimited.
The parameter visible controls, if the display is initially shown.


MConsole

public MConsole(int nbLines,
                int bgColor,
                int textColor,
                int fontSize)
Constructs a MConsole with given maximal number of lines in text buffer, the background color, the default text color and the size of the font (1: small, 2: medium, 3: large)
If nbLines <= 0, the number of lines is unlimited.
The display is initially shown.


MConsole

public MConsole(boolean visible)
Contructs a MConsole with unlimited number of lines, black background, white default text color and large size of font. The parameter visible controls, if the display is initially shown.


MConsole

public MConsole()
Contructs a MConsole with unlimited number of lines, black background, white default text color and large size of font. The display is initially shown.

Method Detail

show

public void show()
Shows the form display if it is not yet visible or it was previously hidden by another display. Because it is not garanteed that the diplay is actually visible when Display.setCurrent() returns, wait for a maximum of 5 s for the display to get shown.


show

public void show(boolean wait)
Shows the console display if it was previously hidden by another display or not yet displayed. If wait = true, block until the display becomes actually visible, up to a maximum auf 5 seconds. This may be useful to observe the start of a calculation.


color

public void color(int textColor)
Changes default text color to given color. The change will only become effective on the next line.


println

public void println(java.lang.String text)
Appends given text to last line, if print() was previously called or start a new line, if no print-method or println() was previously called.


println

public void println()
Starts a new line. Same as println(text) with empty text.


print

public void print(java.lang.String text)
Appends given text to last line, if print() was previously called or start a new line, if no print-method or println() was previously called.


print

public void print(boolean b)
Prints a boolean.


print

public void print(char ch)
Prints a character.


print

public void print(char[] s)
Prints a array of characters.


print

public void print(double d)
Prints a double-precision floating-point number.


print

public void print(float f)
Prints a floating-point number.


print

public void print(int i)
Prints an integer.


print

public void print(long l)
Prints a long integer.


println

public void println(boolean b)
Prints a boolean and advances on next line.


println

public void println(char ch)
Prints a character and advances on next line.


println

public void println(char[] s)
Prints an array of characters and advances on next line.


println

public void println(double d)
Prints a double-precision floating-point number and advances on next line.


println

public void println(float f)
Prints a floating-point number and advances on next line.


println

public void println(int i)
Prints an integer and advances on next line.


println

public void println(long l)
Prints a long integer and advances on next line.


clear

public void clear()
Erases all text and show empty console. Resets color of text to default. The current color of the background is maintained.


clear

public void clear(int bgColor,
                  int textColor)
Erases all text and show empty console and sets background and text colors.


addOkButton

public void addOkButton()
Adds an OK soft button with label "OK". When pressed, the Gidlet's callback notification doOk() is called unless you register your own CommandListener.


addOkButton

public void addOkButton(java.lang.String label)
Adds an OK soft button with given label. When pressed, the Gidlet's callback notification doOk() is called unless you register your own CommandListener.


removeExitButton

public void removeExitButton()
Removes Exit soft button. Gidlet's callback notification doExit() is disabled.


removeOkButton

public void removeOkButton()
Removes Ok soft button. Gidlet's callback notification doOk() is disabled.


init

protected void init()
Initialize MConsole. Called by main() if MConsole is created before main() is called.


keyPressed

protected void keyPressed(int key)
Notificaton of key pressed.

Overrides:
keyPressed in class javax.microedition.lcdui.Canvas

keyRepeated

protected void keyRepeated(int key)
Notification of key repeated.

Overrides:
keyRepeated in class javax.microedition.lcdui.Canvas

keyReleased

protected void keyReleased(int key)
Notification of key release.

Overrides:
keyReleased in class javax.microedition.lcdui.Canvas

paint

protected void paint(javax.microedition.lcdui.Graphics g)
Used for rendering canvas.

Specified by:
paint in class javax.microedition.lcdui.Canvas