且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用JFreeChart< java>将动态折线图添加到现有JFrame中的JPanel中.

更新时间:2023-12-05 19:13:10

使用ProcessBuilder(在在此处显示)执行 SwingWorkerdoInBackground()实现中的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);
    }
}