我的程序中有两个类(main.java和update.java); main.java中包含JTextArea,update用于update.java JTextArea。
我目前无法获得update.java来更新JTextArea - 任何想法?
主
public class Main extends JFrame
{
public JTextArea Requeststxta;
JScrollPane sp_Requeststxta;
Requeststxta = new JTextArea("");
sp_Requeststxta = new JScrollPane(Requeststxta);
getContentPane().add(sp_Requeststxta);
Togglebtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
if (State == "yes")
{
Add.setEnabled(false);
Edit.setEnabled(false);
Delete.setEnabled(false);
Close.setEnabled(false);
State = "no";
Togglebtn.setText("Stop");
Runnable Update = new Update();
Thread StartUpdate = new Thread(UpdateRequests);
StartUpdate.start();
}
else
{
Addbtn.setEnabled(true);
Editbtn.setEnabled(true);
Deletebtn.setEnabled(true);
Closebtn.setEnabled(true);
State = "yes";
Togglebtn.setText("Start");
}
}
});
}
更新
public class UpdateRequests implements Runnable
{
public JTextArea textarea;
@Override
public void run()
{
// TODO Auto-generated method stub
int count = 0;
String ResultsStr = null;
while(true)
{
dbConnector Update = new dbConnector();
try
{
ArrayList<RequestInfo> requests = Update.GetRequests();
for (int i=0; i<requests.size(); i++)
{
ResultsStr = "update please";
}
System.out.println(ResultsStr);
// update jtextarea here
Thread.sleep(5000);
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
其他一切都很好;它只是更新textarea我遇到了麻烦