Java 使用invokeLater更新同一实例中的值
我的程序应该搜索一个计算机名,并在搜索它的GUI的同一个实例中更新计算机名值。如果我启动应用程序并搜索计算机名并点击搜索,它将不会出现在同一实例中。如果我再次点击run,我刚才搜索的计算机名将出现在GUI新实例的标签中 所以基本上现在我必须启动一个新的GUI实例来查看更新后的计算机名。感谢您的帮助。我已经在这上面呆了很长时间了 相关代码:Java 使用invokeLater更新同一实例中的值,java,invokelater,Java,Invokelater,我的程序应该搜索一个计算机名,并在搜索它的GUI的同一个实例中更新计算机名值。如果我启动应用程序并搜索计算机名并点击搜索,它将不会出现在同一实例中。如果我再次点击run,我刚才搜索的计算机名将出现在GUI新实例的标签中 所以基本上现在我必须启动一个新的GUI实例来查看更新后的计算机名。感谢您的帮助。我已经在这上面呆了很长时间了 相关代码: try(BufferedReader br=new BufferedReader(newFileReader(“resultobatch.txt”)) {
try(BufferedReader br=new BufferedReader(new
FileReader(“resultobatch.txt”))
{
你可以在这里查看完整的类:为什么几乎所有的东西都是静态的?这是因为我只是修补代码,试图让它工作。我刚刚删除了静态全局变量。
final Pattern PATTERN = Pattern.compile("CN=([^,]+).*");
try {
while ((sCurrentLine = br.readLine()) != null) {
String[] tokens = PATTERN.split(","); //This will return you a array, containing the string array splitted by what you write inside it.
//should be in your case the split, since they are seperated by ","
// System.out.println(sCurrentLine);
CN = sCurrentLine.split("CN=",-1)[1].split(",",-1)[0];
System.out.println(CN);
testLabel.setText(CN);
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MISControlPanel window = new MISControlPanel();
window.frame.setVisible(true);
//testLabel.setText(CN);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}