---
title: "TextAreaConsole"
author: "mmdev"
date: "2011-12-08T10:08:00Z"
tags: []
slug: "textareaconsole"
draft: false
lastmod: "2011-12-10T16:21:16Z"
id: 1301582
url: "https://mmdev.iteye.com/blog/1301582"
---

TextAreaConsole是JTextArea作为输出，实现了Console(com.teleca.robin.lib.face)的类.

源码文件TextAreaConsole.java如下：

package com.teleca.robin.lib.util;

import javax.swing.JTextArea;

import com.teleca.robin.lib.face.Console;

public classTextAreaConsoleimplements Console{

StringBuffer strBuffer=new StringBuffer();

private javax.swing.JTextArea textArea;

publicTextAreaConsole(JTextArea textArea)

{

this.textArea=textArea;

}

public voidappend(String str) {

// TODO Auto-generated method stub

strBuffer.append(str);

}

public voidclear(){

// TODO Auto-generated method stub

textArea.setText("");

textArea.repaint();

}

public voidflush() {

// TODO Auto-generated method stub

textArea.append(strBuffer.toString());

textArea.repaint();

strBuffer.delete(0, strBuffer.length());

}

public final voidprint(String str) {

// TODO Auto-generated method stub

textArea.append(str);

textArea.repaint();

}

public voidprintln(String str) {

// TODO Auto-generated method stub

textArea.append(str);

textArea.append("\\n");

int len=textArea.getText().length();

textArea.setCaretPosition(len);

textArea.repaint();

}

}

注1：关于Console(com.teleca.robin.lib.face)的更多内容请参照《[**Console**](http://hubingforever.blog.163.com/blog/static/171040579201142572587/ "阅读全文")》。

注2：关于TextAreaConsole的使用可以参照《[**文件删除器(二)**](http://hubingforever.blog.163.com/blog/static/171040579201132734220720/ "阅读全文")》