星期六, 4月 09, 2011

Simple Data Visualization Java Program



I know that other programming languages such Processing or Labview can make data visualization fairly easy. However, because I learned Java recently, I want to try to make a program to show the mouse position.

First, we need a frame and a panel to show the graph.
A panel within a frame. Here is the simple code.

Second, I wrote a function called drawPoint to draw lines. My original thinking is that this function can receive value from external sources. Because if you just want to acquire the mouse position data, we can just get the data and draw in the function. But I didn't.

The function needs an Object Channel argument. This object is to construct an array and an element counter. So, we can add many channels if we want.


Like I said before, the program originally want to get external data. Now, we just try to acquire mouse position, so I need to return the position to the main class.

In the main class, we need to (1) construct a frame, (2) set up channels, and (3) draw the graphs. Pretty easy, right!!