×

Discussion Board

Results 1 to 3 of 3

Thread: stream plotting

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    2

    Red face stream plotting

    i am going to plot a graph for a stream input of data,i used a random function to try it , i acually have a big problem in using copyarea() function ,the main issue here that i want to plot a new input and holding the old graph,when i reach the end of the screen i have to move the graph (canvas) so that i would be able to plot the new incominng data,but when i plot the new incoming data i forced to repaint all the previous data ,i want to use copyarea() function in such away to repaint without need to plot all old data againe and when you try my code the problem will be more obvious for you

    this is my code,
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Graphics;
    import java.util.Random;
    import java.util.Vector;
    /**
    * @author ArNoNcE
    */
    public class TestPlot1 extends MIDlet {
    public void startApp() {
    final VividPlot sweeper = new VividPlot();
    sweeper.start();
    sweeper.addCommand(new Command("Exit", Command.EXIT, 0));
    sweeper.setCommandListener(new CommandListener() {

    public void commandAction(Command c, Displayable s) {
    sweeper.stop();
    notifyDestroyed();
    }
    });

    Display.getDisplay(this).setCurrent(sweeper);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }
    }

    class VividPlot extends Canvas implements Runnable
    { int x1;//define three lines to plot the section under scope
    int x2,x3,xold,x_start;
    int y1,yold;
    int y2;
    int u;//counter for painting
    Vector Rx;
    String v;
    private boolean mTrucking;// to track the plot
    private int mTheta;
    private int mBorder;
    private int mDelay;
    public static Random r=new Random();//declear randon function
    public VividPlot()
    { Rx=new Vector(10, 10);
    mBorder=10;
    mDelay=1;
    xold=0;//getWidth();//start from the end of monitor
    x1=200;//getWidth()-1;
    x_start=200;
    x2=202;//getWidth()-2;
    x3=201;//2getWidth()-2;//width represent the scope area
    y1=y2=yold=getHeight();
    u=0;

    }
    public void start()
    { mTrucking=true;//define and start the thread
    Thread t=new Thread(this);
    t.start();
    }

    public void stop()
    {
    mTrucking=false;//stop plotting

    }
    protected void paint(Graphics graphics)
    {

    graphics.setColor(255, 255, 255);
    graphics.fillRect(0, 0, getWidth(), getHeight());
    graphics.setColor(255, 0, 0);
    y2=40+r.nextInt(40);//mm.plotdata+;
    Rx.addElement(Integer.toString(y2));
    graphics.drawLine( xold,yold,x1,y1);
    graphics.drawLine( x1,y1,x2,y2);


    if(x2==getWidth())
    {
    repaint();

    graphics.setColor(255, 255, 255);
    graphics.fillRect(0, 0, getWidth(), getHeight());
    // graphics.copyArea(x2, y2, 0, getHeight(), 10, 10, graphics.LEFT|graphics.TOP);
    x2=x_start;
    x_start-=2;
    xold=0;//getWidth();
    x1=200;//getWidth()-1;
    x3=x2-1;//2getWidth()-2;//width represent the scope area
    y1=y2=yold=getHeight();
    }

    xold=x1;
    x1=x2;
    yold=y1;// hre we make tansition for eah point to the coming one
    y1=y2;
    x2=x2+1;//move process
    x3=x3+1;
    }

    public void run()
    {

    while (mTrucking) {

    if(x2 < getWidth())
    repaint(x3,0,2,getHeight());
    else
    repaint(x3,0,2,getHeight());

    try { Thread.sleep(mDelay); }
    catch (InterruptedException ie) {}
    }

    }

    }

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,405

    Re: stream plotting

    Hi arnonce,

    checking your code, a problem is that you're using copyArea method on the device display Graphics object. If you check JavaDocs, you'll find this:
    The copyArea method is allowed on all Graphics objects except those whose destination is the actual display device.
    So, to use that method, you should use another Graphics object: for example, you could create a buffer Image, draw your graph on its Graphics object, and finally paint the Image itself on the device Graphics object.

    Hope it helps,
    Pit

  3. #3
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,405

    Re: stream plotting

    This modified (as explained in previous post) version of your code should work (even if, in my opinion, you should try to refactor your code to optimize it):

    Code:
    mport javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Graphics;
    import java.util.Random;
    import java.util.Vector;
    
    /**
     * @author ArNoNcE
     */
    public class TestPlot1 extends MIDlet {
    	public void startApp() {
    		final VividPlot sweeper = new VividPlot();
    		sweeper.start();
    		sweeper.addCommand(new Command("Exit", Command.EXIT, 0));
    		sweeper.setCommandListener(new CommandListener() {
    
    			public void commandAction(Command c, Displayable s) {
    				sweeper.stop();
    				notifyDestroyed();
    			}
    		});
    
    		Display.getDisplay(this).setCurrent(sweeper);
    	}
    
    	public void pauseApp() {
    	}
    
    	public void destroyApp(boolean unconditional) {
    	}
    }
    
    class VividPlot extends Canvas implements Runnable {
    	int x1;// define three lines to plot the section under scope
    
    	int x2, x3, xold, x_start;
    
    	int y1, yold;
    
    	int y2;
    
    	int u;// counter for painting
    
    	Vector Rx;
    
    	String v;
    
    	private boolean mTrucking;// to track the plot
    
    	private int mTheta;
    
    	private int mBorder;
    
    	private int mDelay;
    
    	public static Random r = new Random();// declear randon function
    	
    	Image graph = null;
    
    	public VividPlot() {
    		
    		graph = Image.createImage(getWidth(), getHeight());
    		
    		Rx = new Vector(10, 10);
    		mBorder = 10;
    		mDelay = 1;
    		xold = 0;// getWidth();//start from the end of monitor
    		x1 = 200;// getWidth()-1;
    		x_start = 200;
    		x2 = 202;// getWidth()-2;
    		x3 = 201;// 2getWidth()-2;//width represent the scope area
    		y1 = y2 = yold = getHeight();
    		u = 0;
    
    	}
    
    	public void start() {
    		mTrucking = true;// define and start the thread
    		Thread t = new Thread(this);
    		t.start();
    	}
    
    	public void stop() {
    		mTrucking = false;// stop plotting
    
    	}
    
    	protected void paint(Graphics g)
    	{
    		Graphics graphics = graph.getGraphics();
    		
    		y2 = 40 + r.nextInt(40);// mm.plotdata+;
    		Rx.addElement(Integer.toString(y2));
    		
    		
    
    		if (x2 == getWidth())
    		{
    			 graphics.copyArea(2, 0, getWidth() - 2, getHeight(), 0, 0,
    			 Graphics.LEFT|Graphics.TOP);
    			
    			 graphics.setColor(255, 255, 255);
    			graphics.fillRect(getWidth() - 2, 0, 2, getHeight());
    			 
    			x2 -= 2;
    			xold -= 2;
    			x1 -= 2;
    			x_start -= 2;
    			x3 -= 2;
    		}
    		graphics.setColor(255, 0, 0);
    		graphics.drawLine(xold, yold, x1, y1);
    		graphics.drawLine(x1, y1, x2, y2);
    
    		xold = x1;
    		yold = y1;// hre we make tansition for eah point to the coming one
    		
    		x1 = x2;
    		y1 = y2;
    		
    		x2 = x2 + 1;// move process
    		x3 = x3 + 1;
    		
    		g.drawImage(graph, 0, 0, Graphics.LEFT | Graphics.TOP);
    	}
    
    	public void run() {
    
    		while (mTrucking) {
    
    				repaint();
    
    			try {
    				Thread.sleep(mDelay);
    			} catch (InterruptedException ie) {
    			}
    		}
    
    	}
    
    }
    Pit

Similar Threads

  1. stream plotting
    By arnonce in forum Mobile Java General
    Replies: 0
    Last Post: 2008-06-26, 07:40
  2. Half Duplex Audio Streaming
    By subhrajyotisaha in forum Symbian Media (Closed)
    Replies: 0
    Last Post: 2006-05-25, 04:39
  3. SIP content type
    By hlothman in forum Symbian Networking & Messaging (Closed)
    Replies: 8
    Last Post: 2006-05-17, 09:26
  4. Video stream to nokia 3650
    By auvinent in forum Streaming and Video
    Replies: 5
    Last Post: 2004-01-30, 08:31
  5. RDesWriteStream / RDesReadStream dropping data?
    By edelsesto in forum Symbian
    Replies: 0
    Last Post: 2003-07-12, 07:59

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •