1 Reply Latest reply on Mar 13, 2009 10:20 AM by 843851

    Error draw an image on canvas

      Hello! In this code, the drawImage method is returning false. If the same code is run as a desktop application using the main method the error does not happen.
      Who knows why?
      public class AppJavaTV implements Xlet{
          private XletContext context;
          private Container container;
          private SCanvas canvas;
          public void initXlet(XletContext arg0) throws XletStateChangeException {
              context = arg0;
              container = TVContainer.getRootContainer(arg0);
              canvas = new SCanvas();
              canvas.setLocation(0, 0);
          public void startXlet() throws XletStateChangeException {}
          public void pauseXlet() {}
          public void destroyXlet(boolean arg0) throws XletStateChangeException {}
          public static void main(String argv[]) {
              Frame frame = new Frame();
              frame.setLayout(new BorderLayout());
              frame.add("Center", new SCanvas());
              frame.resize(400, 400);
      public class SCanvas extends Canvas{
          Image img = null;
          public SCanvas(){
              MediaTracker media = new MediaTracker(this);
              img = Toolkit.getDefaultToolkit().createImage("/Image.jpg");
              media.addImage(img, 0);
              try {
              } catch (Exception e) {}
          public void paint(Graphics graphics){
              graphics.drawRect(0, 0, 50, 50);
              if(!graphics.drawImage(img, 200, 200, this))
                  graphics.drawString("Error on draw image", 200, 200);
        • 1. Re: Error draw an image on canvas
          That is because you are using Canvas and Container objects. That objects are not used on the DTV environment. You should use the ones adapted to it, the ones contained in org.havi.ui, like HContainer, HScreen...

          Remember tha java.awt is not used (except for some classes) and the equivalent elements are under org.havi.ui