开发者

List for holding data

i receive float data from the network every 400 ms that i put in 4 arrays of float. I store those arrays in another array, so i have :

float[][] datas = {data1, data2, data3, data4};
FloatData floatData = new FloatData(datas);
model.addFloatData(floatData);

My model has a list of FloatData object and the FloatData object has the method :

float[] getFloatData(int index);

th开发者_如何学Goat returns the array of float that i want. This array is used to paint on a JPanel. So in the painComponent i do the following :

for(FloatData floatData : listOfFloatData) {
floatData.draw(g, index);
}

My question is what kind of list can i use for the listOfFloatData as it will be updated every 400 ms and read in the paintComponent method ? Also, i would like to know a convenient way to pass the listOfFloatData from the model to my view ? I was thinking about using a singleton object holding the listOfFloatData as this list will be used in several components ? Thank you.


Decouple the model from the view by storing your data in a subclass of AbstractTableModel. The flyweight pattern used by JTable is much more efficient at rendering, and you can modify your model as profiling warrants.

Addendum: If you collect data on another thread, using e.g. SwingWorker, you can publish() the data with very low latency, while your process() implementation updates the model on the Event Dispatch Thread. There's an example here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜