我的程序应该搜索计算机名称,并在搜索它的GUI的同一个实例中更新计算机名称值。如果我启动应用程序并搜索计算机名称并点击搜索,它就赢了&# 39; t出现在同一个实例中。如果我再次运行,我刚搜索的计算机名称将出现在GUI新实例的标签中。
所以基本上我必须启动GUI的新实例以查看更新的计算机名称。任何帮助表示赞赏。我现在已经坚持了很长时间。
相关守则:
try (BufferedReader br = new BufferedReader(new
FileReader(" resultofbatch.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();
}
}
});
}
您可以在此处查看完整的课程:http://pastebin.com/8hH1TMD3