I want to introduce simple Java program that performs real-time signal drawing. It based on Model-View-Controller (MVC) framework. I wrote a post about MVC usage by very simple example.
At first, we create a Buffer class, where incoming samples (came from some abstract source) are stored. The idea of how Buffer handles data is shown on Fig.1. The iWrite (iW) index points to cell were new sample is stored. Denote this sample s[0]. The sample that has came before s[0] becomes s[-1], sample before it becomes s[-2] and so on. After new sample saved, the iRead (iR) index increments subsequently to read all samples from newest to oldest to redraw signal on screen. We increment iR to read from s[0] to s[-6]. Repeat that procedure we draw the signal that slide along the screen from right to left.