package com.tur.demo;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
class DataReceiver extends JPanel {
private List values; // 保存接收到的数据的容器.
private static final int MAX_VALUE = 200; // 接收到的数据的最大值.
private static final int MAX_COUNT_OF_VALUES = 50; // 最多保存数据的个数.
public DataReceiver() {
values = Collections.synchronizedList(new ArrayList());
// 使用一个线程模拟产生数据.
new Thread(new Runnable() {
@Override
public void run() {
Random rand = new Random();
try {
while (true) {
addValue(rand.nextInt(MAX_VALUE)); // 产生一个数据,并模拟接收并放到容器里.
repaint();
Thread.sleep(100);
}
} catch (Interru