×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    19

    How is it possible ? (paint problem)

    Hi all !!

    I'm trying to execute this code

    Code:
    	protected void paint(Graphics g) {
    		g.setColor(255,255,255);
    		g.fillRect(0, 0, this.getWidth(), this.getHeight());
    		g.setColor(0,0,0);
    		g.drawString("Loading...", this.getHeight()/3, this.getWidth()/3, Graphics.TOP | Graphics.LEFT);
    		StreamConnection connection = null;
    		InputStream in = null;
    		StringBuffer buffer = new StringBuffer();	
            try {
    			connection = (StreamConnection)
    			Connector.open("http://metalcam.free.fr/brut.php");
    ...
    It's weird because, when I call the class wich extends the canvas... I'm still seeing the "old canvas", with the message "do you accept the request" (because of the Connector), and AFTER accepted, I see that the fillRect has been executed (le background is white).

    Is it normal ? What can I do ?

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: How is it possible ? (paint problem)

    Yes, this is perfectly normal. It's because painting occurs to a buffer, and not to the screen until the paint() method ends.

    My advice is: don't do anything in paint(), except paint. Don't access the network, don't access RMS, don't load anything from the JAR, don't access the file system, don't send text messages, and don't change the state of your application (that is, don't change the values of any non-local variables).

    More generally, don't do anything time consuming (network access, RMS, sleep(), etc.) in any event handler method (like keyPress(), commandAction(), startApp(), etc.) Event methods should always return as quickly as possible.

    Network access needs to happen in a separate thread.

    Graham.

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    19

    Re: How is it possible ? (paint problem)

    Ok thanks I'll try this...

  4. #4
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: How is it possible ? (paint problem)

    Yes, this is normal.

    You should not do any blocking operation in your paint() method as paint will finally be visible to you only after the complete paint method is executed.

    Try to move the connection code to a thread, and if you need start the thread from your paint method.

    thanks,
    ~Amitabh
    (Poster of the Month -Aug'09)
    Follow me on my blog for Innovative Mobile Apps

  5. #5
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: How is it possible ? (paint problem)

    Is there an echo in here...?

  6. #6
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: How is it possible ? (paint problem)

    Sorry, I did'nt saw your reply - I dont know why... may be some network delay/problem on my end.

    thanks,
    ~Amitabh
    (Poster of the Month -Aug'09)
    Follow me on my blog for Innovative Mobile Apps

Similar Threads

  1. kjava canvas paint problem on some nokia devices
    By danielwang99 in forum Mobile Java General
    Replies: 2
    Last Post: 2008-02-05, 17:07
  2. Problem with eglSwapBuffers and heap corruption
    By greatape in forum Symbian Media (Closed)
    Replies: 2
    Last Post: 2007-05-24, 03:35
  3. netcards - Problem with opening adapter
    By kernj in forum Symbian Tools & SDKs
    Replies: 5
    Last Post: 2007-01-10, 08:56
  4. Problem: S60 SDK for CW in PC with .NET
    By anttij in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2005-02-28, 11:36
  5. 7210 Silent Problem
    By MarkMckim in forum Mobile Java General
    Replies: 1
    Last Post: 2003-03-18, 12:36

Posting Permissions

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