更新时间:2023-12-05 19:13:10
使用ProcessBuilder
(在在此处显示)执行 SwingWorker
的doInBackground()
实现中的ping
命令.解析输出,然后结果publish()
.更新您的process()
实现中的数据集,图表将相应地进行更新. 此处.
Using ProcessBuilder
, shown here, execute the ping
command in your doInBackground()
implementation of a SwingWorker
. Parse the output, and publish()
the results. Update the dataset in your process()
implementation, and the chart will update itself in response. An example using JFreeChart
is shown here.
您能再解释一下吗?
Can you explain a bit more?
从第一个示例开始,替换
ProcessBuilder pb = new ProcessBuilder("ls", "-lR", "/");
使用
ProcessBuilder pb = new ProcessBuilder("ping", "-c", "3", "example.com");
可以方便地显示ping
的标准输出.在概述中,第二个示例中的process()
可能看起来像这样:
to get a convenient display of the standard output of ping
. In outline, your process()
in the second example might look like this:
@Override
protected void process(java.util.List<String> messages) {
for (String message : messages) {
textArea.append(message + "\n");
// parse x, y from message
series.add(x, y);
}
}