4 Replies Latest reply: Feb 9, 2010 4:10 AM by 843851 RSS

    HScene repaint sequence


      I'm developing an mhp application that has to render an animation.
      I have tested it on xLetView and on the ADB Stb developer version
      getting the same behavior.

      On an applet when I call a repaint(), internally the system calls
      the update(Graphics g) method... the default implementation
      clears the screen and then calls paint. Often I override this method
      in this way
      public void update(Graphics g) { paint(g); }
      so that no screen clearing is done (this is very useful when you have
      a still image on a background and you don't want to rewrite it every time).

      Going to my xLet... it's a simple snake game. When I call repaint the screen is cleared to the background color every time. So I have overridden the update method... but this method is never called
      (I placed a System.out.println in it and so I'm sure is never called).

      So I looked at the HScene specification... here there is a method
      that tells the HScene not to clear the screen every time... but seems
      to not have any effect...

      so... I can't tell to my xLet to not clear the screen every time... and the update method seems that is never called.

      Anyone can help me? I really don't understand who is clearing the screen every time and how I can avoid this.

      p.s. another little question. If I place the image on the Background device I can solve the problem since the Image isn't rendered by the paint method every time... is it correct? I have good performance improvements in this way? On some documents I read that the background image is managed by the video decoder and so the cpu-processing can avoid to deal with it... if it's true, this technique can be used on every decoder or are there decoders not supporting background images?


        • 1. Re: HScene repaint sequence
          Here is a very short example showing my problem.

          In xLetView I have a red square moving left to right... but I don't want to have a background clear... so I would expect to have a growing red rectangle from left to right...

          What's wrong with this code?

          * Test: simple xLet showing background clear problems
          * Author: Ignazio Locatelli - DotLand srl - (C) 2005

          package giochi.snake;

          import javax.tv.xlet.*;
          import java.io.*;
          import java.awt.*;
          import java.awt.event.*;
          import java.util.*;
          import org.havi.ui.*;
          import org.havi.ui.event.*;
          import org.dvb.ui.*;
          import javax.tv.service.selection.*;

          public class Test extends HComponent implements Xlet, Runnable {

          // xLet context
          private XletContext context;

          // reference to main thread
          private Thread testThread;

          private HScene scene;

          // square x Position
          int xPos = 0;

          public Test() {}

          public void initXlet(javax.tv.xlet.XletContext context) throws javax.tv.xlet.XletStateChangeException {
          this.context = context;

          public void startXlet() throws javax.tv.xlet.XletStateChangeException {
          testThread = new Thread(this);

          public void run() {
          while (true) {
          if (xPos > 300) xPos = 0;
          try {
          } catch(Exception e) {}

          public void getResources() {
               HSceneFactory factory = HSceneFactory.getInstance();
               HSceneTemplate hst = new HSceneTemplate();
                    new org.havi.ui.HScreenDimension(1,1),
                    new org.havi.ui.HScreenPoint(0,0),

               scene = factory.getBestScene(hst);


          Rectangle rect = scene.getBounds();


               // do focus al component

          /** NEVER CALLED!!! WHY? */
          public void update(Graphics g) { paint(g); }

          public void paint(Graphics g) {

          System.out.println("fill mode: " + scene.getBackgroundMode() + " mode fill = " + scene.BACKGROUND_FILL);
          g.setColor(new Color(200,0,0));

          public void pauseXlet() {

          public void destroyXlet(boolean unconditional) throws javax.tv.xlet.XletStateChangeException {
               if (unconditional) {
               } else {
               throw new XletStateChangeException("May I stay alive?");

          public void doPause() {

          public void doDestroy() {
               scene = null;

          • 2. Re: HScene repaint sequence
            Surfing the web I realized that update isn't called on lightweight components...

            And the xLet is an extension of a simple Component (or HComponent) and so it's a lightweight component.

            So... ok... update isn't called. But why my component background is cleared everytime? maybe is the HScene to which the component is added to perform a background clear?
            • 3. Re: HScene repaint sequence
              try to use:


              insted of repaint.
              • 4. Re: HScene repaint sequence
                Thank you, your answer help me so much.