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 class
TextAreaConsole
implements Console{
StringBuffer strBuffer=new StringBuffer();
private javax.swing.JTextArea textArea;
public
TextAreaConsole(JTextArea textArea)
{
this.textArea=textArea;
}
public void
append
(String str) {
// TODO Auto-generated method stub
strBuffer.append(str);
}
public void
clear()
{
// TODO Auto-generated method stub
textArea.setText("");
textArea.repaint();
}
public void
flush
() {
// TODO Auto-generated method stub
textArea.append(strBuffer.toString());
textArea.repaint();
strBuffer.delete(0, strBuffer.length());
}
public final void
print
(String str) {
// TODO Auto-generated method stub
textArea.append(str);
textArea.repaint();
}
public void
println
(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》。