Results 1 to 5 of 5
  1. #1
    aneuryzma is offline Member
    Join Date
    Aug 2008
    Posts
    46
    Rep Power
    0

    Default why my image is not updated ?

    This code does not work.

    public void paintComponent(Graphics g) {

    img = Toolkit.getDefaultToolkit().createImage(bMconnecti on.getNextImage());

    i++;
    g.drawImage(img,5,20,this);
    g.fillOval(i, i, 10, 10);
    repaint();
    }

    The testing oval works but my image is not displayed. why ?

    If I move the first line outside of the paintComponent method it works but i can capture only the first frame of the video..

    should I use another method instead of to create it each time ?

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Do not load images in the paintComponent method. Load them into a collection or array at construction and access them in/from the collection/array as needed in the painting code.

  3. #3
    aneuryzma is offline Member
    Join Date
    Aug 2008
    Posts
    46
    Rep Power
    0

    Default

    I have a camera streaming, and I need to update the image in loop. How can I do this outside the paint method ? should I implement a thread ?

    The problem is the code works only if

    img = Toolkit.getDefaultToolkit().createImage(bMconnecti on.getNextImage());

    is in the panel constructor...

    thanks

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,390
    Rep Power
    25

    Default

    Put the loading on its own thread and call repaint() after each image is loaded.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    he has been already a similar recommendation in the sun java forums.

Similar Threads

  1. Number of updated records
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-21-2008, 04:32 PM
  2. How to accurately test if timezone data is updated?
    By Santhosh in forum Advanced Java
    Replies: 0
    Last Post: 11-14-2007, 06:53 AM
  3. Updated Forum Rules
    By levent in forum Suggestions & Feedback
    Replies: 1
    Last Post: 08-12-2007, 01:09 PM
  4. Replies: 7
    Last Post: 08-11-2007, 09:44 PM
  5. Replies: 1
    Last Post: 08-07-2007, 05:13 AM

Posting Permissions

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