newestLine = currentLine;
newestLine = currentLine.getContent();
    public void keyPressed(KeyboardEvent ke) {        //  make sure we are ready to intercept the keyboard        if (!isActive) return;        switch (ke.getKeyCode()) {        //  intercept the up and down arrow keys        case KeyEvent.VK_UP:            ke.consume();            if (historyIndex == -1) {                newestLine = currentLine;                historyIndex = history.size();            }            historyIndex--;            redisplay();            break;        case KeyEvent.VK_DOWN:            ke.consume();            if (historyIndex == history.size() - 1)                historyIndex = -2;            else if (historyIndex == -1) newestLine = currentLine;            historyIndex++;            redisplay();            break;        case KeyEvent.VK_LEFT:            //Left the cursor goes left            ke.consume();            if (posOnCurrentLine > 0) {                posOnCurrentLine--;                refreshCurrentLine();            }            break;        case KeyEvent.VK_RIGHT:            // Right the cursor goes right            ke.consume();            if (posOnCurrentLine < currentLine.length()) {                posOnCurrentLine++;                refreshCurrentLine();            }            break;        case KeyEvent.VK_HOME:            // The cursor goes at the start            ke.consume();            posOnCurrentLine = 0;            refreshCurrentLine();            break;        case KeyEvent.VK_END:            // the cursor goes at the end of line            ke.consume();            posOnCurrentLine = currentLine.length();            refreshCurrentLine();            break;        //  if its a backspace we want to remove one from the end of our current        // line        case KeyEvent.VK_BACK_SPACE:            ke.consume();            if (currentLine.length() != 0 && posOnCurrentLine > 0) {                posOnCurrentLine--;                currentLine = currentLine.substring(0, posOnCurrentLine)                        + currentLine.substring(posOnCurrentLine + 1,                                currentLine.length());                refreshCurrentLine();            }            break;        //  if its a delete we want to remove one under the cursor        case KeyEvent.VK_DELETE:            ke.consume();            if (posOnCurrentLine == 0 && currentLine.length() > 0) {                currentLine = currentLine.substring(1);            } else if (posOnCurrentLine < currentLine.length()) {                currentLine = currentLine.substring(0, posOnCurrentLine)                        + currentLine.substring(posOnCurrentLine + 1,                                currentLine.length());            }            refreshCurrentLine();            break;        //  if its an enter key we want to process the command, and then resume        // the thread        case KeyEvent.VK_ENTER:            out.print(ke.getKeyChar());            ke.consume();            posOnCurrentLine = 0;            synchronized (this) {                isActive = false;                threadSuspended = false;                notifyAll();            }            break;        // if it's the tab key, we want to trigger command line completion        case KeyEvent.VK_TAB:            ke.consume();            if (posOnCurrentLine != currentLine.length()) {                String ending = currentLine.substring(posOnCurrentLine);                currentLine = complete(currentLine.substring(0,                        posOnCurrentLine))                        + ending;                posOnCurrentLine = currentLine.length() - ending.length();            } else {                currentLine = complete(currentLine);                posOnCurrentLine = currentLine.length();            }            break;        default:            //  if its a useful key we want to add it to our current line            if (!Character.isISOControl(ke.getKeyChar())) {                ke.consume();                if (posOnCurrentLine == currentLine.length()) {                    currentLine += ke.getKeyChar();                } else {                    currentLine = currentLine.substring(0, posOnCurrentLine)                            + ke.getKeyChar()                            + currentLine.substring(posOnCurrentLine);                }                posOnCurrentLine++;                refreshCurrentLine();            }        }    }