-3
我有一个名为JTextArea和JButton的主JFrame。 当我按下按钮时,线程会在屏幕后面执行某些操作并记录日志。 线程正在执行其工作时,日志将更新为JtextArea。 教程仅向我展示基本功能。所以我不知道该怎么做。 感谢您的阅读。多线程:如何让jframe更新一个线程的日志?
我的线程类:
public class myThread implements Runnable{
private Thread t;
public String getThreadName() {
return ThreadName;
}
public void setThreadName(String ThreadName) {
this.ThreadName = ThreadName;
}
public void setIsDone(boolean isRunning) {
this.isDone = isDone;
}
public boolean getIsDone() {
return this.isDone;
}
private String Log;
public String getLog() {
return Log;
}
public void setLog(String Log) {
this.Log = Log;
}
private String ThreadName;
public boolean isDone=false;
public myThread(String strThreadName)
{
this.ThreadName=strThreadName;
this.isDone=false;
}
@Override
public void run() {
creatingFolerCreating();
}
private void createingFolerCreating()
{
String strResultFolder=this.Path+"\\"+"Result";
this.strAFolder=strResultFolder+"\\"+"A";
this.strBFolder=strResultFolder+"\\"+"B";
boolean s=false;
s=(new File(strResultFolder)).mkdir();if(!s)this.Log+="result Foleder is existed";
s =(new File(strAFolder)).mkdir();if(!s)this.Log+="A Foleder is existed";
s =(new File(strBFolder)).mkdir();if(!s)this.Log+="B Foleder is existed";
}
public void start()
{
if(t==null)
{
t=new Thread(this,this.ThreadName);
t.start();
this.isDone=true;
}
}
}
对不起,多线程的新手。但是在Rannable类中,如何调用textArea?没有什么可以连接textArea(JFrame)和线程。感谢您的帮助。 – Hanata
无论如何感谢帮助我。我从你的例子中得到了很多想法。非常感谢。在myRunnable类的构造函数中,我将textArea传入。非常感谢。 – Hanata
请原谅我,因为迟到的答案。 关于你的问题,也许有点困惑,但真的很简单。正如你所看到的,这个类在另一个代表应用程序的类中,我的意思是它是本地的,这就是Runnable类可以看到它的成员容器类的原因。希望这个帮助 –