JTextField tf=new JTextArea(100,20);
tf.setText(“OK”);
tf.setText(“OK”);
解决方案 »
- 在做磁盘文件搜索的时候出现了空指针!
- 怎么得到一个字符串的引用
- java能不能直接连接操作sql server的.mdf数据文件而不经过sql server2005
- 如下JAVA代码为什么画不了圆?
- 使用jdom生成xml,xml中包含pdf文件流的问题
- jtable的行数增减
- 使用被弃用的方法到底对程序有没有影响?
- hashtable的bug?
- ★★女朋友要过生日了!我想用java为她写一个程序,一举两得啊! 希望大家多提建议啊!谢谢!!!
- 有没有高人用过freejava,拜托,帮个忙!
- 关于eclipse里调试的问题!
- 如何将System.out.println();的内容转向到座JTextField控件中
import java.awt.event.*;
import java.io.*;public class PrintTest extends PrintStream{ JTextField field = null; public PrintTest(JTextField field) throws Exception{
super(System.out);//呵呵
this.field = field;
} public void print(String str){
if(field!=null){
field.setText(str);
}
} public void println(String str){
if(field!=null){
field.setText(str);
}
} public static void main(String[] args) throws Exception{
JFrame f = new JFrame("Test");
JTextField Field=new JTextField();
f.getContentPane().add(Field,BorderLayout.CENTER);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
PrintTest pt = new PrintTest(Field);
System.setOut(pt);
f.setSize(200,100);
f.show();
Thread t=new TestThread();
t.start();
}}
class TestThread extends Thread{
public void run(){
try{
for(int i=0;i<10;i++){
System.out.println("hehe,test "+i);
sleep(500);
}
}catch(Exception ex){
System.out.println(ex.toString());
}
}
}